Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

(SOLVED) Server script refuses to FireClient()?

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

###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)

4 comments

0

^ This answer should be accepted

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?

0

Nevermind, solved it.

0

my bad but you should have indexed it

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

1 comment

0

This should be a comment.

This discussion is preserved as it was. New answers, comments, and votes are closed.