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

How to use remote events/functions?

Asked by
AZDev 590 Moderation Voter
9 years ago

I have no real experience with either of these so any help is appreciated.

I have created scripts that work if filtering enabled is not on. I now need to rewrite them for filtering enable due to my game being exploited.

Here is what needs to happen in pseudo.

01--[[
02When the player clicks create a new part.
03Set the parts CFrame to the part in the gun called main.
04Give the part a parent.
05Add the part to game service "debris" to be removed after 2 seconds.
06Make the part black.
07Scale the part to the smallest size possible.
08Give the part a velocity.
09When the part hits something check for a humanoid.
10If the part finds a humanoid then get the player from character.
11respawn the player who was hit.
12Add 1 to the shooters kills.
13Add 1 to the deaths of the player shot.
14--]]

My attempts to do this with filtering enabled respawned the shooter, not the person who was shot.

0
I use respawn instead of killing the player because it is an airsoft game. Later when the player is hit it will play an animation then respawn the player. AZDev 590 — 9y

1 answer

Log in to vote
3
Answered by 9 years ago

So, you'll want a remote event to trigger in order to respawn a hit player. You can't do this on the client side (the LocalScript side), so you'll have to use a RemoteEvent object.

On the server, you'll take the RemoteEvent and give it the player respawn logic, like so:

1local event = game.ReplicatedStorage.RemoteEvent --replace with wherever the RemoteEvent is
2event.onServerEvent:connect(function(player, toRespawn)
3    -- resppawn the player here
4end)

Note that fact that you get the player that called the event automatically in the arguments.

On the client, you'll do this:

1local event = game.ReplicatedStorage.RemoteEvent --replace with wherever the RemoteEvent is
2--when the person is hit. The variable of the hit player is 'toRespawn'
3event:FireServer(toRespawn)

This tutorial explains more.

0
Thanks this helped. Game now respawns the correct player. Now my only problem is that only the shooter can see that the gun is being fired. AZDev 590 — 9y
Ad

Answer this question