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

Custom Money adding command isnt working, help?

Asked by 4 years ago
Edited 4 years ago

Info: this is for a meme game i am making (inferno is an admin) and i was making a command that gives everyone money, but in testing it doesnt work, everything is spelt correctly and works in the in-game console.

local function MoneyStorm()
    local allPlayers = game.Players:GetChildren()
    for i = 1, #allPlayers do
        allPlayers[i].leaderstats.despacitcoin.Value = allPlayers[i].leaderstats.despacitcoin.Value + 500
    end
end

local players = game:GetService("Players")
game.Players.PlayerAdded:connect(function(player) 
    if player.Name == "xInferno_Dragonx" or player.Name == "pokemonzizzle8383" then 
        player.Chatted:connect(function(msg)
            if msg:lower() == "MoneyStorm!" then
             MoneyStorm()()


            end
        end)
    end
end)

EDIT: cant tell if this helps but the "despacitcoin" goes up by 20 every 10 seconds on a loop in another script

Edit 2: after the if i put Print("success") however it didnt print, meaning the problem must be before the if statment.

Edit 3: the error seems to be coming from "if msg:lower() == "MoneyStorm!" then" after doing more testing, however i cant seem to locate the problem

0
Why are there two parentheses around your function call? You also declared the Players service, no need to write game.Players, you must also use :Connect(). Lowercase :connect() is deprecated. Ziffixture 6913 — 4y
0
the two parentheses were accidental but removing them and re-capitalising did nothing to help pokemonzizzle8383 6 — 4y
0
there is multiple if statements so i dont know which one you are talking about, also use the player id not the name. Code1400 75 — 4y
0
After if msg:lower() pokemonzizzle8383 6 — 4y

1 answer

Log in to vote
0
Answered by
NotedAPI 810 Moderation Voter
4 years ago

You should use ID's instead of their name and use string.lower().

local WhitelistedIDs = {}
--[[
    Example table:
    local WhitelistedIDs = {1, 1361134044} | Add a comma after each ID
]]

local PlayerService = game:GetService("Players")

local function MoneyStorm(player)
    player.Chatted:Connect(function(msg)
        if string.lower(msg) == 'moneystorm!' then --// Lowers chat
            for index, id in pairs(WhitelistedIDs) do --// Loops through WhitelistedIDs table
                if player.userId == id then --// If the matches one of the IDs in the table
                    for index, plr in pairs(PlayerService:GetPlayers()) do --// Gets all players
                        plr.leaderstats.despacitcoin.Value = plr.leaderstats.despacitcoin.Value + 500 --// Adds value
                    end
                end
            end
        end
    end)
end

PlayerService.PlayerAdded:Connect(MoneyStorm)
Ad

Answer this question