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

Why can't I use RemoteEvent:FireAllClients?

Asked by 3 years ago

I want to check whether a character is in a Region3 at a certain time on the server, so I made a remote event called FloorCheck. Now, I put this in my main Script when I want to check:

if game.ReplicatedStorage:FindFirstChild("FloorCheck") then
    print("FloorCheck exists")
end
game.ReplicatedStorage.FloorCheck:FireAllClients()

Here is what I put in a LocalScript:

script.Parent.FloorCheck.OnClientEvent:Connect(function()
    print("Recieved FloorCheck RemoteEvent")
    local RegionThree = Region3.new(564.523, 3.261, 23.901,518.588, 8.317, 57.639)
    local Parts = workspace:FindPartsInRegion3(RegionThree)
    if table.find(Parts, game.Players.LocalPlayer.Character.HumanoidRootPart)==nil then
        game.Players.LocalPlayer.Character.Humanoid.Health=0
    end
end)

Now I see FloorCheck exists but no Recieved FloorCheck RemoteEvent in the output. Why? How can I fix this?

0
put the local script in starter player scripts (do like game.repstorag.floorcheck.onclientevent). i think you would also want the fireallclients line inside the if statement BulletproofVast 1033 — 3y

1 answer

Log in to vote
0
Answered by
NGC4637 602 Moderation Voter
3 years ago
Edited 3 years ago

This is a common mistake.

you cannot put local scripts outside of the local player, or the local player's character. so put the local script in StarterPlayerScripts or StarterCharacterScripts instead. Or else, the local script won't work.

also, a part of the local script is wrong as well. you should've done this:

script.Parent.FloorCheck.OnClientEvent:Connect(function()
    print("Recieved FloorCheck RemoteEvent")
    local RegionThree = Region3.new(Vector3.new(564.523, 3.261, 23.901),Vector3.new(518.588, 8.317, 57.639))
    local Parts = workspace:FindPartsInRegion3(RegionThree)
    if table.find(Parts, game.Players.LocalPlayer.Character.HumanoidRootPart) == nil then
        game.Players.LocalPlayer.Character.Humanoid.Health=0
    end
end)
0
I changed line 3 of the local script. You can check what i changed NGC4637 602 — 3y
Ad

Answer this question