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

Adding arguments to remote events?

I'm trying to make my game filtering enabled, but I'm having a whole lot of troubles with remoteevents.

Let's say I wanted to do a 'Damage' event. I tried this script:

script.Damage.OnServerEvent:connect(function(player,value)
	game.Players[player].Character.Humanoid.Health = game.Players[player].Character.Humanoid.Health - value
end)

Now, that wouldn't work, because player and value would be the same thing, leading me to my question. How would I add arguments to a remote event?

I can't seem to get this one. All help appreciated!

1 comment

0

Added a code block

2 answers

A RemoteEvent being fired from the client automatically sends the first argument, as the player. By 'Player', it's referring to the Instance of a Player.

script.Damage.OnServerEvent:connect(function(player,value)
	player.Character.Humanoid.Health = player.Character.Humanoid.Health - value -- since player is already a child of 'game.Players', I can directly referrence it.
end)

2 comments

0

My problem is, though, value is being recognized still as "Player".

0

@BloxBlocker if you fire the event as so: :FireServer(1234), 1234 being the value, it'll work.

When you do :FireServer() you don't need to do :FireServer(game.Players.LocalPlayer, 10) since the first argument is automatically recieved. So if you do

remote:FireServer(10)

The value would be 10

remote.OnServerEvent:connect(function(playerWhoFired, Damage)
	print(Damage) --// 10
end)

playerWhoFired is the player object so you can just do playerWhoFired.Character or your way it would be game.Players[playerWhoFired.Name].Character

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