Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to insert a Remote Event by Touch?

Asked by 8 years ago

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.

0
you don't reffer to the PlayerGui's like "game.Players.PlayerName.PlayerGui" you directly do player.PlayerGui to access it. iDarkGames 483 — 8y
0
Either works though BlackJPI 2658 — 8y
0
There's not a lot right here... Perci1 4988 — 8y
0
I made the script shorter as to say it's full of unrelated things to my question, if it really is necessary I can edit the question to have the full script, I'm trying to make the script generate a RemoteEvent called LabDialogEvent to playergui by hitting a certain brick. I just can't make the script generate it inside playergui. I tried iDarkGames' suggestion but it says that "PlayerGui is not a Eleenrei 0 — 8y
0
valid part" and I tried making it go to game.Players, it worked well except it would be outside of a player, and not inside of a Player, PlayerName doesnt work for some reason for me. How can I make it go directly to playergui? Eleenrei 0 — 8y

Answer this question