Hey there. Apologies, I am a beginner coder - and I am stumped. I’m trying to use this simple script (located in Workspace) to activate and run a LocalScript that is located in StarterGui for a dialogue system.
The Script in Workspace inside of a part:
local TouchEventOne = game.Workspace.TouchEventOne
TouchEventOne.Touched:Connect(function(Object)
if Object.Parent:FindFirstChild("Humanoid") then
local player = game.Players[Object.Parent.Name]
print("Dialogue One!")
dialogueone:Play()
script.Parent:Destroy()
end
end)
The LocalScript in StarterGui I am trying to activate with the above:
local RemoteEvent = game.ReplicatedStorage.RemoteEvent
local dialogue = plr.PlayerGui:WaitForChild("DialogueBar").Dialogue
local function OnClient)
print ("Dialogue One Starting!")
dialogue.Visible = true
end
RemoteEvent.OnClientEvent:Connect(RemoteEvent)```
I am extremely stumped and would love to know the best way to continue from here. Is there a good method for doing this? I tried using a RemoteEvent and it didn't work for me. Thank you for taking your time to assist me!
1 Like
So from what I’m getting, are you wanting to connect the RemoteEvent from the server to the client?
Exactly. Also, but each time I try and call it via the server - I don’t get a response, not even an error. I am extremely stumped.
I gotcha, well it’s actually pretty simple
So, if you’re wanting to fire the RemoteEvent that way we use the function that’s called FireClient
which requires 1 argument for it to work:
- The
Player
object (Or game.Players.MistahTwist for clarification)
Now you wonder, how can you get the Player a easier way? We can actually use the GetPlayerFromCharacter
function which is basically what it is: Gets the Player object from a Character
model so
local TouchEventOne = game.Workspace.TouchEventOne
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
TouchEventOne.Touched:Connect(function(Object)
if Object.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(Object.Parent) --Since Object is the HitPart, we can use Object.Parent to get the Parent (Or the Character)
if player then --This is checking if the player that touched the part is a valid Character model
Event:FireClient(player) --We're passing the Player object onto this
print("Dialogue One!")
dialogueone:Play() --Idk what you defined what this is so I'll just leave it as it is
script.Parent:Destroy()
end
end
end)
And on your LocalScript:
local RemoteEvent = game.ReplicatedStorage.RemoteEvent
local dialogue = plr.PlayerGui:WaitForChild("DialogueBar").Dialogue
local function OnClient()
print ("Dialogue One Starting!")
dialogue.Visible = true
end
RemoteEvent.OnClientEvent:Connect(OnClient)
I did rush a bit to get this working, but if you have any more questions just feel free to ask
1 Like
Couldn’t have been more helpful. Thank you so much, you have my respect!
1 Like