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

playerpoint rain on command help?

Asked by 9 years ago
local isAdmin = {[""] = true, [""] = true, [""] = true}

function onChatted(message, player)
    if message == "pprainplz" and isAdmin[player.Name] then
        game.Workspace.PPRain.Disabled = false
game.Players.PlayerAdded:connect(function(player)
    player.Chatted:connect(function(message) onChatted(message, player) end)
end)

Ive tried to do this but it wont work when i say pprainplz to make it rain the parts from the other script, and i know the other works because i've tried it

0
Please put in code block. EzraNehemiah_TF2 3552 — 9y
0
sorry, its in code block now. TheDarknessHasRisen 5 — 9y

1 answer

Log in to vote
1
Answered by 9 years ago

The PlayerAdded event in this code will never run because it is inside the onChatted function which is never called. You are also missing multiple end's in your code.

local isAdmin = {[""] = true, [""] = true, [""] = true}

function onChatted(message, player)
    if message == "pprainplz" and isAdmin[player.Name] then
        game.Workspace.PPRain.Disabled = false
    end
end

game.Players.PlayerAdded:connect(function(player)
    player.Chatted:connect(function(message) 
        onChatted(message, player)
    end)
end)

To further improve this code you can use a function to check if the player is in the table. So you do not have to set each player to true. This function is also not case sensitive.

I also only call the onChatted function if the player is considered an admin. This allows for less code repetition if you wish to make multiple admin commands.

local isAdmin = {"Bob", "Joe"}

function inAdminTable(Name)
    for _,n in pairs(isAdmin) do
        if n:lower() == Name:lower() then
            return true
        end
    end
end

function onChatted(message, player)
    if message == "pprainplz"  then
        game.Workspace.PPRain.Disabled = false
    end
end

game.Players.PlayerAdded:connect(function(player)
    if inAdminTable(player.Name) then
        player.Chatted:connect(function(message) 
            onChatted(message:lower(), player)
        end)
    end
end)
0
Thank you so much! TheDarknessHasRisen 5 — 9y
Ad

Answer this question