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

Works in studio but not in Play Online?

Asked by 9 years ago

Whenever I run this in studio everything works perfect and resets the values, but if I run it by going to the place and clicking Play. It doesn't reset any values.

reset.MouseButton1Down:connect(function()
    for i,v in pairs(game.Players:GetPlayers()) do
        for k,val in pairs(v.leaderstats:GetChildren()) do
            if val:IsA("IntValue") then
                val.Value=0
            elseif val:IsA("StringValue") and val.Name=="Promotion" then
                val.Value="No"
            end
        end
    end
end)

Part of a larger code.

1 answer

Log in to vote
1
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

In the code you provided, you didn't define 'reset' on line 1. It's nil. Unless you meant to make a connection statement, in that case you would have to do..

function reset()
    for i,v in pairs(game.Players:GetPlayers()) do
        for k,val in pairs(v.leaderstats:GetChildren()) do
            if val:IsA("IntValue") then
                val.Value=0
            elseif val:IsA("StringValue") and val.Name=="Promotion" then
                val.Value="No"
            end
        end
    end
end

script.Parent.MouseButton1Down:connect(reset)

But ultimately, we can't help you unless you supply the whole script, and output if there is any.

Make sure this is a localscript.

Ad

Answer this question