i have a script that when they touch a certain part a GUI appears on their screen. and the same for whe they leave the part but the GUI goes away. When i go to test it, it appears but it then goes away and doesnt come back... and whenever they sit in a chair it goes away. why?
This is a server script in the workspace
script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid")then if game.Players[hit.Parent.Name].Name == script.Parent.Owner.Value then game:GetService("ReplicatedStorage").RemoteEvents.Workplace1JobEvent:FireServer() end end end) script.Parent.TouchEnded:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then if game.Players[hit.Parent.Name].Name == script.Parent.Owner.Value then game:GetService("ReplicatedStorage").RemoteEvents.Workplace1JobEvent.End:FireServer() end end end)
this is a Local Script inside of the player scripts
game:GetService("ReplicatedStorage").RemoteEvents.Workplace1JobEvent.OnServerEvent:Connect(function(plr) print(plr) local gui = game.Players.LocalPlayer.PlayerGui.ShopGui.Workplace1 if game.Players.LocalPlayer.PlayerGui.ShopGui.Workplace1.Started.Value == false then gui.Started.Value = true gui.Visible = true gui.Needed.Value = math.random(250,600) gui.Current.Value = 0 else gui.Started.Value = true end return end) game:GetService("ReplicatedStorage").RemoteEvents.Workplace1JobEvent.End.OnServerEvent:Connect(function(plr) game.Players.LocalPlayer.PlayerGui.ShopGui.Workplace1.Visible = false return end)
if anyone is able to help me with this i would really appreciate it, i have been struggling with it for hours now.
Edit: the problem is with the .TouchEnded part because something is triggering it and im not sure what.
OnServerEvent
can only be listened for by the server. Use OnClientEvent
instead. You're also calling FireServer
on the server, which will throw an error. Use FireClient
instead.-- localscript local plr = game:GetService("Players").LocalPlayer -- use more variables! local Remotes = game:GetService("ReplicatedStorage").RemoteEvents -- Remotes.Workplace1JobEvent.OnClientEvent:Connect(function() -- no player local gui = plr.PlayerGui.ShopGui.Workplace1 if not plr.PlayerGui.ShopGui.Workplace1.Started.Value then-- use not to check falsey values gui.Started.Value = true gui.Visible = true gui.Needed.Value = math.random(250,600) gui.Current.Value = 0 else gui.Started.Value = true end end) Remotes.Workplace1JobEvent.End.OnClientEvent:Connect(function() plr.PlayerGui.ShopGui.Workplace1.Visible = false end)
local Players = game:GetService('Players') local Remotes = game:GetService("ReplicatedStorage").RemoteEvents script.Parent.Touched:Connect(function(hit) local plr = Players:GetPlayerFromCharacter(hit.Parent) if plr then if plr.Name == script.Parent.Owner.Value then Remotes.Workplace1JobEvent:FireClient(plr)-- player to fire to end end end) script.Parent.TouchEnded:Connect(function(hit) local plr = Players:GetPlayerFromCharacter(hit.Parent) if plr and plr.Name == script.Parent.Owner.Value then Remotes.Workplace1JobEvent.End:FireClient(plr) end end end)