I'm trying to call a RemoteEvent to a player that touched a part but i can't seem to figure out how to get it to call the Event.
Here is the script: local Replicated = game:GetService("ReplicatedStorage") local Radio = Replicated:WaitForChild("Sounds"):FindFirstChild("Radio")
script.Parent.Touched:connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then Radio:FireClient(hit.Parent.Name) --Gets an error here. end end)
Any help would be appreciated!
You're getting the error "Unable to cast value to Object" because you're trying to pass a string. Also, the first argument needs to be the player you're invoking, then whatever you want to send.
script.Parent.Touched:connect(function(hit) if hit and hit.Parent then local player = game.Players:GetPlayerFromCharacter(hit.Parent) if player then -- Player you're invoking, then the model. Radio:FireClient(player, hit.Parent) -- Other Example: Radio:FireClient(player, 'hi') end end end)
The Response in your LocalScript would be
Radio.OnClientEvent:connect(function(object) print(object) -- Player1 -- Other Example prints 'hi' end)