When a player touches temp his leaderboard will change to the value of temp, if a player touch tamp theirs will change to that value.
Why in one script? Less lag.
Temperature (Model) > MasterScript
TAMP (part) TEMP (part)
local ting = 0 function onTouched(hit) if ting == 0 then ting = 1 check = hit.Parent:FindFirstChild("Humanoid") if check ~= nil then local user = game.Players:GetPlayerFromCharacter(hit.Parent) local stats = user:findFirstChild("leaderstats") if stats ~= nil then local cash = stats:findFirstChild("F") if cash.Value >= 0 then cash.Value = cash.Value == 23 end local cash = stats:findFirstChild("C") if cash.Value >= 0 then cash.Value = cash.Value == ("-5") end script.Parent.TAMP.Touched:connect(onTouched) end if stats ~= nil then local cash = stats:findFirstChild("F") if cash.Value >= 0 then cash.Value = cash.Value == 34 end local cash = stats:findFirstChild("C") if cash.Value >= 0 then cash.Value = cash.Value == 1 end script.Parent.TEMP.Touched:connect(onTouched) end end ting = 0 end end
These are all of your problems with this script:
1.
:findFirstChild()
is deprecated, use :FindFirstChild()
2.
To change the value of a number:
local cash = script.CashValue cash.Value = 1 -- changes the value cash.Value = cash.Value + 1 -- adds 1 to the value cash.Value = cash.Value - 1 -- takes away 1 from the value cash.Value = cash.Value * 2 -- multiplies the value by 2 cash.Value = cash.Value / 2 -- divides the value by 2
3.
To make sure something is a player:
script.Parent.Touched:connect(function(hit) local p = game.Players:GetPlayerFromPlayer(hit.Parent) -- an npc can have a humanoid if p then -- code end end)