Edit: Fixed it
I'm trying to make a Dialog GUI that took me numerous tries to perfect. Currently so far it works whenever a player connects inside the game. The problem is, I need to make it work when a player passes through a certain block. The script is supposed to run, make something called LabDialogEvent inside PlayerGui and enable a certain local script which would try to find LabDialogEvent.
function OnTouched(hit) --game.Players.PlayerAdded:connect(function(player) script.Parent.Touched:connect(function(player) local event = Instance.new("RemoteEvent") event.Parent = player event.Name = "LabDialogEvent" event:FireClient(player) wait(1) game.Players.LocalPlayer.PlayerGui.LabDialogScript.Disabled = false
I already commented out the spawn script, but It just wont insert a remote event inside the PlayerGui. It still works as intended when the commented line is used and the third line removed. I tried making event.Parent specificly go to PlayerGui but due to my amateurish scripting knowledge. game.Players.PlayerName.PlayerGui won't work. Any help or ideas how it could work?
Edit:
function OnTouched(hit) script.Parent.Touched:connect(function(player, hit) game.workspace.activatelight3:Destroy() local event = Instance.new("RemoteEvent") event.Parent = game.Players.LocalPlayer.PlayerGui.LabDialogScript event.Name = "LabDialogEvent" event:FireClient(player) print('Event Fired to Client successfully') game.Players.LocalPlayer.PlayerGui.LabDialogScript.Disabled = false
After trying to experiment a lot of things, i found out that LocalPlayer works instead of PlayerName. It might have conflicts in the future but it works for now. LabDialogScript receives the remoteevent, finds the event in its child and it fully works.