So I want to make a sensor that detects if a player touched it and fire a remote event into the client and then make a dialogue box appear, but I keep getting this one error:
I can’t fire a remote event from the server to the client without getting this error, I scoured throughout the devforum but could not find a way to reference the player generally.
Workspace:
Server Script:
local remoteEvent = game.ReplicatedStorage.Room1SensorEvent
local sensor = script.Parent
local Player = game:GetService("Players")
sensor.Touched:Connect(function(hit)
local character = hit.Parent
local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
if humanoidRootPart then
remoteEvent:FireClient(hit)
end
end)
Local Script:
local remoteEvent = game.ReplicatedStorage.Room1SensorEvent
local player = game:GetService("Players").LocalPlayer
local roboDialogue = game.StarterGui.Dialogues.RobotDialogue
remoteEvent.OnClientEvent:Connect(function(player)
roboDialogue.Visible = true
print("All secure!")
end)
The player is actually hit, what you told the client in the server script.
remoteEvent:FireClient(hit)
So, the local script would look like this:
local remoteEvent = game.ReplicatedStorage.Room1SensorEvent
local player = game:GetService("Players").LocalPlayer
local roboDialogue = game.StarterGui.Dialogues.RobotDialogue
remoteEvent.OnClientEvent:Connect(function(hit)
roboDialogue.Visible = true
print("All secure!")
end)
local remoteEvent = game.ReplicatedStorage.Room1SensorEvent
local sensor = script.Parent
local Player = game:GetService("Players")
sensor.Touched:Connect(function(hit)
local character = hit.Parent
local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if humanoidRootPart then
remoteEvent:FireClient(player, hit)
end
end)
Client:
local remoteEvent = game.ReplicatedStorage.Room1SensorEvent
local player = game:GetService("Players").LocalPlayer
local roboDialogue = game.StarterGui.Dialogues.RobotDialogue
remoteEvent.OnClientEvent:Connect(function(hit)
roboDialogue.Visible = true
print("All secure!")
end)
local remoteEvent = game.ReplicatedStorage.Room1SensorEvent
local sensor = script.Parent
local Player = game:GetService("Players")
sensor.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then -- Checks if they have a humanoid
local character = hit.Parent
local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if humanoidRootPart then
remoteEvent:FireClient(player, hit)
end
end
end)
The sensor could be hitting anything and it would fire.
This line below would return nil if it can not get the character back.
local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)