Client OnTouch Script makes value go up for every player

I want to make that, when a player touches a part, his value would go up, which works, but not only for him.


(Player1 touched the part, this is what he sees.)


(Player2 did nothing, but the value went up.)


(Here is the script in explorer and his properties.)

local part = script.Parent
local player = game.Players.LocalPlayer.Character
local function onTouch(player)
	print(game.Players.LocalPlayer.Name.." is becoming "..script.Parent.Name)
	game.Players.LocalPlayer.PlayerGui.FurryMeter.FurryValue.Value += 1
end

local function onTouchEnded(player)
end

part.Touched:Connect(onTouch)
part.TouchEnded:Connect(onTouchEnded)

Here is the code I am using.

1 Like

You need to check if the player that touched the part is the local player, it detects every players.

1 Like

And how can I do that?
I tried…

BTW the instance in Touched is a part, not a player.

local part = script.Parent
local player = game.Players.LocalPlayer
local function onTouch(touchpart)
    if touchpart.Parent == player.Character then
       print(player.Name.." is becoming "..part.Name)
	   player.PlayerGui.FurryMeter.FurryValue.Value += 1
    end
end

part.Touched:Connect(onTouch)

I also noticed that you’re doing this in client side, not sure how it will work but I don’t think it should work like that.

1 Like

Seems to work, thank you!


(Player1 walked through the puddle.)

(Player2 did nothing, when Player1 walked through the puddle.)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.