script.Parent.Touched:connect(function(hit) if hit.Name =="REMOVER" then local Player=game.Players:GetPlayerFromCharacter(hit.Parent) Player.leaderstats.Score.Value = Player.leaderstats.Score.Value + 1 end end)
I'm trying to figure out leaderstats rn. I want it so that when the handle of a tool touched the part REMOVER, 1 is added to leaderstats. Therefore, I made this script, and put it in the handle...
Its not working. i tried fixing it, i'm new to lua, and i can't find the problem. What should I do?
Check your code carefully, mistakes like this will be reduced as you get more experienced in coding.
if hit.Name == "REMOVER" then
In this line, you want to define hit as REMOVER, which in case it is, the script goes on to line 3.
local Player=game.Players:GetPlayerFromCharacter(hit.Parent)
In this line, you must remember that REMOVER is now hit's parameter and thus hit.Parent is not krutik55, but instead the parent of REMOVER.
Solution:
local Player=game.Players:GetPlayerFromCharacter(script.Parent.Parent.Parent)
Explanation: A tool is a descendant of a player when equipped. (krutik55.Tool.Handle.Script), hence the 3 ".Parent"s