Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Button that gives a +1 to a leaderstat works in studio but not in game?

I have it in a button, it works perfectly fine in studio but doesnt in game. There's no errors either.

local Player = script.Parent.Parent.Parent
local Humanoid = Player.Character.Humanoid
local value = "Power"

script.Parent.Train.MouseButton1Click:Connect(function()
	wait(1)
    Player.leaderstats[value].Value = Player.leaderstats[value].Value + 1
    local health = Humanoid.Health
    local power = Player.leaderstats[value].Value
    local newhealth = health*power
    Humanoid.MaxHealth = newhealth
end)

1 comment

0

This doesn't work in game because of FilteringEnabled, in FE, clients don't replicate to the server, so you'll have to use remote events to change things like leaderstats

3 answers

✓ Accepted answer

Try this! (LOCALSCRIPT)

local Player = game:GetService("Players").LocalPlayer
local Humanoid = Player.Character:WaitForChild("Humanoid")
local Power = Player:FindFirstChild("leaderstats"):WaitForChild("Power")

script.Parent.Train.MouseButton1Click:Connect(function()
       Power.Value = Power.Value +1
     
      Humanoid.MaxHealth = Humanoid.Health*Power.Value
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.