The issue here is that you're attempting to run a local script in workspace. Local scripts can only run in places which reference the local player (i.e. Backpack, StarterGui, or any place that is a descendant of the player object at some point). To fix this, we'll use a server script to handle the Touched event and fire a remote event to the client, where the Gui will be enabled.
local leave = script.Parent
local remote = Instance.new("RemoteEvent")
remote.Parent = game:GetService("ReplicatedStorage")
leave.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
remote:FireClient(player,"")
end
end)
local player = game:GetService("Players").LocalPlayer
local remote = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
remote.OnClientEvent:Connect(function(args)
local Dialouge2 = player.PlayerGui:FindFirstChild("ScreenGui")
if Dialouge2 then
Dialouge2.Enabled = true
wait(2)
Dialouge2.Enabled = false
end
end)
Resources:
Acceptable Places for Local Scripts (below first paragraph)
Accept and upvote if this helped!
2 comments
Can't you just use the .Touched event in a single localscript?
no, they dont run in workspace