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
8 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.

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

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 — 8y

1 answer

Log in to vote
3
Answered by 8 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:

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

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

On the client, you'll do this:

local event = game.ReplicatedStorage.RemoteEvent --replace with wherever the RemoteEvent is
--when the person is hit. The variable of the hit player is 'toRespawn'
event: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 — 8y
Ad

Answer this question