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

(SOLVED) Server script refuses to FireClient()?

Asked by 6 years ago
Edited 6 years ago

Basically I have a local script that fires a remote event and the server script gets the player's mouse target. I try to then use the mouse target to fire the specific client. Even when I verify that the player exists in game.Players the script says it is Unable to cast a value to Object.

I've simplified the code to only show the FireClient() part of the script.

script.Parent:WaitForChild("ArrestPlayer").OnServerEvent:Connect(function(player, mouse_target)
    if game:GetService("Players"):FindFirstChild(mouse_target) then
        print("yes")
        game:GetService("ReplicatedStorage").GameEvents.Tools.ArrestCoreUI:FireClient(mouse_target)
    else
        print("no")
    end
end)

and in the local script I use .Name so I have no idea why it wouldn't work?

local mouse_target = mouse.Target.Parent.Name
script.Parent:WaitForChild("ArrestPlayer"):FireServer(mouse_target)

Any help would be appreceiated

2 answers

Log in to vote
0
Answered by 6 years ago

This is because you're trying to fire a remote event to a string. The first argument to FireClient is a player to fire to.

script.Parent:WaitForChild("ArrestPlayer").OnServerEvent:Connect(function(player, mouse_target)
    if game:GetService("Players"):FindFirstChild(mouse_target) then
        print("yes")
        game:GetService("ReplicatedStorage").GameEvents.Tools.ArrestCoreUI:FireClient(
            player,
            mouse_target
        ) 

    else

        print("no")
    end
end)

0
^ This answer should be accepted RiskoZoSlovenska 378 — 6y
0
"mouse_target" is the name of the client I want to fire, it wasn't working so on line 2 I checked if it did exist and if it did then it would fire the client. Can you help me? Warfaresh0t 414 — 6y
0
Nevermind, solved it. Warfaresh0t 414 — 6y
0
my bad but you should have indexed it User#19524 175 — 6y
Ad
Log in to vote
-2
Answered by 6 years ago

you need to specify the player in the :FireClient()

0
This should be a comment. User#19524 175 — 6y

Answer this question