Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago

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)
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 CPF2 406 — 6y

3 answers

Log in to vote
1
Answered by 6 years ago

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)
Ad
Log in to vote
0
Answered by
1VoyX 5
6 years ago

Try putting that code into a local script (if it isn't already in one) and if it doesn't work while in a local script then go off of what CPF2 said. You can read up on Remote Events here: https://wiki.roblox.com/index.php?title=Remote_Functions_%26_Events

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Answer this question