Increasing a value for player who touched a part

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to make when a player touches a part a value increase and when i try to access it from a local script it gives me the same value
  2. What is the issue? Include screenshots / videos if possible!
    I used a local script to detect when someone is touching a part then change value
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried searching for someone with the same problem but i found nothing
local Db = {}
script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") and not Db[hit.Parent] then
		Db[hit.Parent] = true
		if not game.Players:GetPlayerFromCharacter(hit.Parent) then return end
		local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if Player ~= game.Players.LocalPlayer then return end
		game.ReplicatedStorage.TNT.Damage.Value += 1
		script.Parent:Destroy()
	end
end)

Do you want this value to change on the server too, or just for this player?

I want it to change the value for the player only

Well it’s probably best to store the value somewhere else instead of ReplicatedStorage. For example, a folder in StarterPlayerScripts. I’ve not used Value instances that much so I don’t know where everyone else would put them.

I’d rather create an attribute set to the player instance itself. Plus, you should not do Touched events on the client.

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