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

Firing server with param doesn't seem to be working. Any help?

I decided to take some of my old gun scripts and convert them to a handcuff script.

It uses raytrace to determine who to arrest. The code is a little messy. I will try and clean it up as much as possible.

When the player with the handcuffs is within 5 studs of a play then we need to arrest the player. I do this by changing the player's teamcolor to the teamcolor set for the prisoners and then attempt to reload their character. Because the script is local I need to use a remote event to load their character.

When my code finds a humanoid it then gets the player's player object belonging to humanoid.Parent. I then fire my remote event to server to handle reloading the character.

My Arrest script Attempt1

	script.Parent.RemoteEvent.OnServerEvent:connect(function(player)
		player:LoadCharacter()
	end)

Attempt2

	script.Parent.RemoteEvent.OnServerEvent:connect(function(player, arrestedplayer)
		arrestedplayer:LoadCharacter()
	end)

Fire the event with params Attempt1

	if humanoid then
		local arrestedplayer = game.Players:GetPlayerFromCharacter(humanoid.Parent)
		arrestedplayer.TeamColor = game.Teams.Jail.TeamColor
		--arrestedplayer:LoadCharacter()
		script.Parent.RemoteEvent:FireServer(arrestedplayer)
	end

Attempt2

	if humanoid then
		local arrestedplayer = game.Players:GetPlayerFromCharacter(humanoid.Parent)
		arrestedplayer.TeamColor = game.Teams.Jail.TeamColor
		--			arrestedplayer:LoadCharacter() -- Doesn't work in local script
		script.Parent.RemoteEvent:FireServer(player, arrestedplayer) -- player param is defined by the local player
	end

When I arrest a player the arrested player's teamcolor is changed but my character reloads. This is the same with both attempts.

1 comment

0

More info: The main script is local, the arrest script is a server script, the remote event is parented to the tool, and both scripts are parented to the tool.

1 answer

✓ Accepted answer

When you call the FireServer method of RemoteEvents, it will automatically pass an argument for the LocalPlayer of the client that invoked the server. Any other arguments you pass will come after that.

LocalScript

remoteEvent:FireServer("Hello World!")

ServerScript

remoteEvent.OnServerEvent:connect(function(player, ...)
    print(...)
end)

Output

Hello World!

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