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

[SOLVED]I made a code script but it functions right when the person joins?

Asked by 5 years ago
Edited 5 years ago
function money(amount)
    print('plz')
    plr:WaitForChild("Zeni").Value = plr.Zeni.Value + amount    
end

function power(amountt)
    print("working?")
    plr:WaitForChild("Stats"):WaitForChild("Strength").Value = plr.Stats.Strength.Value + amountt
    print('strength+')
end

plr = game.Players.LocalPlayer
Input = script.Parent.Parent.CodeInput
Enter = script.Parent
codes = {
["Release!"] = money(1000000),

["Beta!"] = power(5000000),

["ITS OVER 9000!!!"] = power(9000)
}



Enter.MouseButton1Click:Connect(function()
    local test = codes[Input.Text]
    print(test.."  this is it!")--says you can't concatenate nil
    if test then
        print('Valid')--doesn't print
        test()
    else
        print("Not")--does print
    end
end)

Also when I join my value goes up by 5000000 and also when I die it goes up by 5000000.

1 answer

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

I know you fixed this but I'll post my answer which probably won't work here anyways..

To fix this, you just need to remove () from the functions, and instead put the arguments when you call them.

Like this:

function money(amount)
    print('plz')
    plr:WaitForChild("Zeni").Value = plr.Zeni.Value + amount    
end

function power(amountt)
    print("working?")
    plr:WaitForChild("Stats"):WaitForChild("Strength").Value = plr.Stats.Strength.Value + amountt
    print('strength+')
end

plr = game.Players.LocalPlayer
Input = script.Parent.Parent.CodeInput
Enter = script.Parent
codes = {
["Release!"] = {money, 1000000}, -- remove and replace

["Beta!"] = {power, 5000000},

["ITS OVER 9000!!!"] = {power. 9000}
}



Enter.MouseButton1Click:Connect(function()
    local test = codes[Input.Text]
    print(test.."  this is it!")--says you can't concatenate nil
    if test then
        print('Valid')--doesn't print
        test[1](test[2])
    else
        print("Not")--does print
    end
end)

Ad

Answer this question