I have a Spinning Part that is being cloned on a local script every time a player joins.
I did that because I noticed some lag if the part is on the Server. The part is supposed to kill every player that touches it. The problem is that when a player touches the part, a remote event is fired from the client to the server and when the remote event is fired, it kills all the players instead of the player that touches the part only.
Local Script:
game.ReplicatedStorage:WaitForChild("SpinningParts"):Clone().Parent = workspace.ObbyMap["Stage 10Special"]
game.ReplicatedStorage:WaitForChild("SpinnerS6"):Clone().Parent = workspace.ObbyMap["Stage 6Special"]
function onTouched(part)
local h = part.Parent:findFirstChild("Humanoid")
local p = game.Players:GetPlayerFromCharacter(part.Parent)
if p and h then
print(p.Name)
game.ReplicatedStorage:WaitForChild("DamagePlayerOnS6"):FireServer(p)
end
end
game.workspace.ObbyMap["Stage 6Special"].SpinnerS6.Lava.Touched:Connect(onTouched)
game.Workspace.ObbyMap["Stage 6Special"].SpinnerS6.Lava1.Touched:Connect(onTouched)
The first argument of a RemoteEvent callback will always be the player who called it. You should have a second argument on that connected function that’s gonna be what the client is sending.
Also the remote is exploitable an exploiter can fire a signal to kill everyone. Might be better to just use a server side touched event or kill the player locally.
Common problem with a local touched event. Other players can trigger other players local touched events:
It triggers the remote for every player and hence kills all players.
Just have the local script check if the touching player is the LocalPlayer, and then fire and empty signal to the server. You can keep the server script as it is!
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local debounce = true
ReplicatedStorage:WaitForChild("SpinningParts"):Clone().Parent = workspace.ObbyMap["Stage 10Special"]
ReplicatedStorage:WaitForChild("SpinnerS6"):Clone().Parent = workspace.ObbyMap["Stage 6Special"]
function onTouched(part)
local check = part:IsDescendantOf(Players.LocalPlayer.Character)
local player = Players:GetPlayerFromCharacter(part.Parent)
if check and debounce then
debounce = not debounce
print(player.Name)
ReplicatedStorage:WaitForChild("DamagePlayerOnS6"):FireServer(player)
debounce = not debounce
end
end
workspace.ObbyMap["Stage 6Special"].SpinnerS6.Lava.Touched:Connect(onTouched)
workspace.ObbyMap["Stage 6Special"].SpinnerS6.Lava1.Touched:Connect(onTouched)