I have “Gold” as an object in my leaderstats, however it’s always 0 when I read from it, here’s the code:
local players = game:GetService("Players")
function onTouched(hit)
if game.Players:FindFirstChild(hit.parent.name) then
local humanoid = hit.parent:FindFirstChild("Humanoid")
if humanoid then
local player = players:GetPlayerFromCharacter(hit.parent)
local leaderstats = player:FindFirstChild("leaderstats")
local woodStats = leaderstats:FindFirstChild("Wood")
local goldStats = leaderstats:FindFirstChild("Gold")
warn(goldStats.Value)
--warn(player)
if goldStats.Value >= 250 then
goldStats.Value -= 250
humanoid.JumpPower += humanoid.JumpPower * 10/100
end
end
end
end
script.Parent.Touched:Connect(onTouched)
I’m changing the value of gold object here on gui button click:
local players = game:GetService("Players")
local player = players.LocalPlayer
local screenGui = player.PlayerGui:WaitForChild("ScreenGui")
local goldButton = screenGui:WaitForChild("TestGold")
local jumpPowerButton = screenGui:WaitForChild("BuyJumpHeight")
local humanoid = players.LocalPlayer.Character.Humanoid
local leaderstats = player:FindFirstChild("leaderstats")
local woodStats = leaderstats:FindFirstChild("wood")
local goldStats = leaderstats:FindFirstChild("Gold")
goldButton.Activated:Connect(function()
print("Added gold")
goldStats.Value += 525
warn(goldStats.Name)
end)
jumpPowerButton.Activated:Connect(function()
print("Jump power added")
if goldStats.Value >= 250 then
goldStats.Value -= 250
humanoid.JumpPower += humanoid.JumpPower * 10/100
end
end)
is it possible that im writing in a place and reading from a completely different place?