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

Why is script affecting the whole server when touching a brick?

Why is script affecting the whole server when touching a brick?

Sorry if my wording was wrong with the question title but I have this problem. Basically I'm trying to make the brick that when touched will basically give the player that touched the brick an increase of stats. The only problem is that whenever this happenes it affects everyone in the server giving them and increase of stats.

Attempts

I've tried many attempts alot having to do with filtering enabled.

  1. I tried firing the touched event in the client and then giving the stats in the server

  2. I tried firing the touched event in the server and giving that stats in the client

Recap:

I'm Trying to make a script where the player who touched the brick recieves and increases of stats but its affecting the whole server.

Local Script

local Player = game.Players.LocalPlayer


game.Workspace.DeathPart.Touched:Connect(function(hit)
	game.ReplicatedStorage.RemoteEvent:FireServer(hit)
end)

Server Script


game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(Player,hit)
	Player.Stats.Strength.Value = Player.Stats.Strength.Value + 1
		Player.Stats.Armour.Value = Player.Stats.Armour.Value + 1
		Player.Stats.Regen.Value = Player.Stats.Regen.Value + 1
		Player.Stats.Agility.Value = Player.Stats.Agility.Value + 1
		Player.Stats.Stamina.Value = Player.Stats.Stamina.Value + 1
		Player.Stats["DiceD-Rank"].Value = Player.Stats["DiceD-Rank"].Value + 1
		if hit.Parent:FindFirstChild("Humanoid") then
			local ehum = hit.Parent:FindFirstChild("Humanoid")
			ehum.Health = ehum.Health - 10
		end
end)

Don't mind the health subtracting stuff

Regards, Bl_ueHistory>

1 answer

You have to check if the part that was touched is from the player, else if anything touches it the player will still be affected:

local Player = game.Players.LocalPlayer


game.Workspace.DeathPart.Touched:Connect(function(hit)
	if Player.Character and hit.Parent == Player.Character then--Checks if player have character and if part that touched is from the character
		game.ReplicatedStorage.RemoteEvent:FireServer(hit)
	end
end)

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