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

Adding arguments to remote events?

Asked by 8 years ago

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!

0
Added a code block Shawnyg 4330 — 8y

2 answers

Log in to vote
0
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
8 years ago

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)
0
My problem is, though, value is being recognized still as "Player". NewVoids 97 — 8y
0
@BloxBlocker if you fire the event as so: :FireServer(1234), 1234 being the value, it'll work. Shawnyg 4330 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

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

Answer this question