As @txcIove said, you’re trying to reference leaderstats
before it’s added to the player. Also, you’re assigning your fortnite
variable to the value of what the value’s value is at the time you assign it. If you do it like that, it won’t update with the value.
Also, it seems that you added the listener inside of the function, which means it won’t listen unless the function is ran at least once. Simple fix, just move the listener outside of the function body.
--vari
local fortnite = game.Players.LocalPlayer:WaitForChild("leaderstats").Money
--end
local debounce = true
function onTouched(hit)
if (hit.Character:FindFirstChild("Humanoid") ~= nil and debounce == true) then
debounce = false
end
if fortnite.Value >= 25 then
fortnite.Value = fortnite.Value - 25
local h = Instance.new("Hat")
local p = Instance.new("Part")
h.Name = script.Parent.Parent.Name
p.Parent = h
p.Position = hit.Character:FindFirstChild("Head").Position
p.Name = "Handle"
p.formFactor = 0
p.Size = Vector3.new(0,-0.25,0)
p.BottomSurface = 0
p.TopSurface = 0
p.Locked = true
script.Parent.Mesh:clone().Parent = p
h.Parent = hit.Character
h.AttachmentPos = Vector3.new(0,-0.25,0)
hit.Character.Hair.Transparency = 1
end
wait(5)
debounce = true
end
script.Parent:WaitForChild("ClickDetector").MouseClick:Connect(onTouched)