I am having problems with the functionality of a script and I don't know how to solve it.
In the images below attach photos of the in-game problem, this means that the whole script works and in-game the property of the visible "bframe" is false but in-game this is not shown and I want to know how I can solve it ..
in-game mode the visibility of the "Bframe" it becomes false in the property (that's fine) but in-game this is not seen..
Does anyone know how to solve it?
Button script
-- Events
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Evento = ReplicatedStorage.RemoteEvent
-- end of Events
local button = script.Parent
local frame = script.Parent.Parent.Parent.Frame
Evento.OnClientEvent:Connect(function(argumento1)
button.MouseButton1Click:Connect(function()
if frame.Visible == false then
frame.Visible = true
button.Visible = false
else
frame.Visible = false
end
end)
end)
Server script
-- Events
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Evento = ReplicatedStorage.RemoteEvent
-- end of Events
game.Players.PlayerAdded:Connect(function(player)
Evento:FireClient(player,"argumento1")
print("testing probado")
end)
Redteam / touch part script called script
local wll = script.Parent.Part
local fr = game.StarterGui.TeamChangerGui.BFrame
local function Toch()
fr.Visible = false
fr.button.Visible = false
print("visible desactivado")
end
wll.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
Toch()
end
end)
**images**
enter image description here
enter image description here
enter image description here
Is the button script a localscript? if it is then it may be to do with the fireclient although I am not good at it and I usually use fireallclients passing through the player name then checking if its the correct name on the clients side script.
Otherwise I am not sure as it is an interesting issue i have never encountered. Hope it works!
Related
I wrote a door save system.
That is, if the user previously bought them, then when re-entering the game, they must be open.
My code works, but the door doesn't save at all.
-- DoorsDataStore
-- Save Stats Doors
local opend = false
local datastorage = game:GetService("DataStoreService")
local isitopen_1 = datastorage:GetDataStore("Door")
game.Players.PlayerAdded:Connect(function(player)
local boolValueDoors = Instance.new("Folder")
boolValueDoors.Name = "BoolValueDoors"
boolValueDoors.Parent = player
local door_1 = Instance.new("BoolValue")
door_1.Parent = boolValueDoors
door_1.Name = "BoolValueDoor_1"
door_1.Value = isitopen_1:GetAsync(player.UserId)
print("True or False")
print(player.BoolValueDoor_1.Value)
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, erromsg = pcall(function()
isitopen_1:SetAsync(player.UserId, player.BoolValueDoor_1.Value)
end)
if erromsg then
warn("Error")
end
end)
-- TouchDoor
script.Parent.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if (humanoid ~= nil) then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player.leaderstats.Coins.Value >= script.Parent.Price.Value then
player.leaderstats.Coins.Value -= script.Parent.Price.Value
player.leaderstats.Level.Value += 1
script.Parent:Destroy()
player.BoolValueDoors.BoolValueDoor_1.Value = true
print("Save Door")
end
end
end)
I tried writing this code in different ways, in different versions, tried through validation. My code still doesn't do what I want.
There are multiple possible problems I see:
1.
SetAsync takes a string as the first argument, you are giving it a number value. To fix this use tostring(player.UserId)
2.
When the player first joins, the value will be set to nil, because there is no data in the datastore under the UserId, and nil is not a boolean.
I’m not sure if these are actual issues and I currently cannot check if these are real problems because I’m not on my computer but they may be something you want to change.
Also it would be nice to know if you encountered any errors when executing the code.
You should also make trigger a remote event that opens the door on the clientside in the PlayerAdded function if the value is true.
I am starting to program in roblox, and I am making a Menu only for users who have a gamepass, I would like to know how I can make an exclusive graphical interface appear when a user has a gamepass, and the error here is that when a user buy that gamepass automatically the exclusive interface is activated to all the users of the server, I would like to know how to fix this problem.
The Script is on ServerScriptService
local MarketPlaceService = game:GetService("MarketplaceService")
local GamePass = 100725261
local Tool = game.StarterGui.ScreenGui.TPMenu
function compra(jugador)
local loTiene = false
local success, errorMensaje = pcall(function()
loTiene = MarketPlaceService:UserOwnsGamePassAsync(jugador.UserId, GamePass)
end)
if loTiene then
game.StarterGui.ScreenGui.TPMenu.Visible = true
end
end
game.Players.PlayerAdded:Connect(function(player)
compra(player)
end)
I tried to made this in a LocalScript and is not working
StarterGui is put into each Player's PlayerGui after they spawn, so editing it for one user would mean that other users would also see the changes after respawning. A better option would be to modify PlayerGui instead, like this:
function compra(jugador)
local loTiene = false
local success, errorMensaje = pcall(function()
loTiene = MarketPlaceService:UserOwnsGamePassAsync(jugador.UserId, GamePass)
end)
if loTiene then
jugador.CharacterAdded:Connect(function() -- Ran every time the player spawns
workspace:WaitForChild(jugador.Name) -- Wait for player to finish spawning
jugador.PlayerGui.ScreenGui.TPMenu.Visible = true
end)
end
end
Keep it as a Script in ServerScriptService.
So I decided to make a jump boost gamepass in roblox but when I test and I have my gamepass it doesn't work.
here is my code
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local PlayerUserID = Players.LocalPlayer.UserId
print(PlayerUserID)
Players.LocalPlayer.CharacterAdded:Connect(function(char)
print(MarketplaceService:UserOwnsGamePassAsync(PlayerUserID, 21723718))
if MarketplaceService:UserOwnsGamePassAsync(PlayerUserID, 21723718) then
char.Humanoid.UseJumpPower = true
char.Humanoid.JumpPower = 100
end
end)
it is a server script on ServerScriptService
I cant see any output that comes from the script.
You cannot use LocalPlayer in a Server Script. You will have to get the player via other methods.
Check out the Roblox gamepass guide.
Your server script is targeting an object that doesn't exist. game.Players.LocalPlayer is only defined in localscripts.
To get around this, use Players.PlayerAdded
Use this code instead
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
if MarketplaceService:UserOwnsGamePassAsync(PlayerUserID, 21723718) then
char.Humanoid.UseJumpPower = true
char.Humanoid.JumpPower = 100
end
end)
end)
can someone help me with that? I already got the code for resetting but when i open chat and say rrrrrrr, i keep dying.
here it is:
local player = game:GetService("Players").LocalPlayer
local character = player.Character
local enabled = true
local userinputservice = game:GetService("UserInputService")
userinputservice.InputBegan:connect(function(input)
if input.KeyCode == Enum.KeyCode.R and enabled then
character.Head:Remove()
enabled = false
wait(6)
enabled = true
end
end)
UserInputService#inputBegan gives you gameProcessedEvent as the second parameter of the function.
It indicates whether the game engine internally observed this input and acted on it. Generally, this refers to UI processing, so if a button was touched or clicked from this input, gameProcessedEvent would be true. This applies to TextBoxes, such as the chat.
All you need to check if if gameProcessedEvent is true.
local UserInputService = game:GetService("UserInputService");
local PlayersService = game:GetService("Players");
UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
if gameProcessedEvent then return false end
if (input.KeyCode == Enum.KeyCode.R) then
PlayersService.LocalPlayer.Character.Head:Destroy()
end
end)
I'm a new developer to roblox and figured it would be a good place to start learning to make games. I was working on my game today and I ran into an issue. I wanted to press 'E' while by a NPC and I got that to work. The only problem was, I have no clue how to make the GUI appear and Dissapear when I press E. This is what I have written,
local HumanoidRootPart = game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart")
local UIS = game:GetService("UserInputService")
local Npc = game.Workspace.Noob.Head
UIS.InputBegan:connect(function(keyCode)
if keyCode.keyCode == Enum.KeyCode.E then
if (Npc.Position - HumanoidRootPart.Position).magnitude < 15 then
game.StarterGui.TextF.TextLabel.Visible = 0
wait(3)
game.StarterGui.TextF.TextLabel.Visible = 1
end
end
end)
it comes out with no error. The code to press E still works, but the GUI does not pop up. I have tried setting the values to True or False
I've Figured it out. if anyone is looking at this question and wondering, this script is almost ok. The only problem is that you cannot change a GUI from the starter GUI, you have to call it from LocalPlayerGui Like this:
local HumanoidRootPart = game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart")
local UIS = game:GetService("UserInputService")
local Npc = game.Workspace.Noob.Head
UIS.InputBegan:connect(function(keyCode)
if keyCode.keyCode == Enum.KeyCode.E then
if (Npc.Position - HumanoidRootPart.Position).magnitude < 15 then
print("Key E was pressed")
game.Players.LocalPlayer.PlayerGui.TextF.TextLabel.Visible = true
wait(3)
game.Players.LocalPlayer.PlayerGui.TextF.TextLabel.Visible = false
end
end
end)