Hi my names are Pixeluted I want to do if player touch to part then GUI open but first time open second time does not open I don’t know why I using Script
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local Player = game.Players:FindFirstChild(hit.Parent.Name)
Player.PlayerGui.ShopGui.Enabled = true
end
end)
Here’s a quick note: you should handle all GUI related things on the client. So instead of using those lines, do:
local Part = -- the part that will open the GUI
local GUI = -- the GUI that will open
Part.Touched:Connect(function()
if hit.Parent:FindFirstChild("Humanoid") then
GUI.Enabled = true
end
end)
May you please send us a video of the problem? I don’t see any problem with the script and the question is very vague.
i think i know your problem. you will need to use a remote event to make this work do
this
Server Script
–part thats being touched
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
game.ReplicatedStorage.EVENTNAMEHERE:FireClient(Player)
end
end)
When I change around guis with a server script, it still works for me. I think it doesn’t matter whether it changes on the server, or changes on the client.
@Lp_MewFX Remote events are the reason for hacking, not prevent . In addition, there is no info to be sent, and it won’t be “faster”. Sorry if I sounded rude.
There are 2 solutions to this problem, but I will show you the easiest one. I recommend adding a LocalScript inside of StarterPlayer -> StarterCharacterScripts and this code:
workspace.YourPartNameHere.Touched:Connect(function(hit)
if hit.Parent.Name == script.Parent.Name then
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
Player.PlayerGui.ShopGui.Enabled = true
end
end)
Change “YourPartNameHere” to the Part’s name.
(note: I have not tested this code, so if there are any issues please tell me.)
script.Parent.Touched:Connect(function(Touched)
local Player = game.Players:GetPlayerFromCharacter(Touched.Parent)
if Player then
Player.PlayerGui:WaitForChild(“ShopGui”).Enabled = true
end
end)
When you do it from the server, the server will recognise Enabled as true. When the client hides the Gui and sets Enabled to false, the server will not see this. Therefore, when it attempts to set Enabled again, the server believes it’s already enabled and won’t do anything.
You should be doing this work from the client-side.
It is not really. I’m using it from a LocalScript, he’s using it from a Server script. It’s not recommended to enable/disable UIs from the server because then if the client disables it, the server can’t see that it disabled it and when it goes to enable it again it won’t work because it thinks it’s enabled, just as @colbert2677 said.