I made a gate, with a invisible wall, so players cannot leave, when they touch it text appears. But it will not show.
local leave = script.Parent local player = game.Players.LocalPlayer local Dialouge2 = player.PlayerGui.ScreenGui local function YouTried(leave) local parent = leave.Parent if game.Players:GetPlayerFromCharacter(parent) then Dialouge2.Enabled = true wait(2) Dialouge2.Enabled = false end end leave.Touched:Connect(YouTried)
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.
--Server script in part 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,"") --you can send any data through the second argument end end) --Local script in acceptable place, such as the ones listed above local player = game:GetService("Players").LocalPlayer local remote = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent") remote.OnClientEvent:Connect(function(args) --the data you sent local Dialouge2 = player.PlayerGui:FindFirstChild("ScreenGui") if Dialouge2 then --ensure existence 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!
local leave = script.Parent local player = game.Players.LocalPlayer local Dialouge2 = player.PlayerGui.ScreenGui leave.Touched:Connect(function(hit) local Player = game.Players:GetPlayerFromCharacter(hit.Parent) if player then Dialouge2.Enabled = true wait(2) Dialouge2.Enabled = false end end)