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

How do I make my function execute?

Asked by
jtefurd 50
9 years ago

I'm quite new to using the Chatted method, I still don't fully understand on how to use it. The function will not execute. It doesn't output any errors either.

admins={"iKxtiee","jtefurd","Player","Player1"}
function onChatted(msg)
    if msg == ":regenblocks" then
        game.Workspace.Blocks:Destroy()     
        local blocks=game.Lighting.Blocks:Clone()
        blocks.Parent=game.Workspace
for _,v in pairs(blocks:GetChildren()) do
    for i=1,0,-.01 do
        v.Transparency=i
        wait(.05)
    end
end     
        print("Blocks have regenerated! :)")
    end
end
game.Players.admins.Chatted:connect(onChatted
0
Why mark this as a bad post? He didn't break any rules! minikitkat 687 — 9y

2 answers

Log in to vote
1
Answered by 9 years ago

First off all the script isn't finished. The last line is:

game.Players.admins.Chatted:connect(onChatted --Opened parentheses! Not good!

game.Players.admins.Chatted:connect(onChatted) --Looks better.

Next, game.Players.Admin doesn't exist.

print(#game.Players.Admin:GetChildren()) --doesn't print 4, which is how many people are admins.

The chatted event only runs in the player. We used player added to do that.

game.Players.PlayerAdded:connect(function(player)
end)

We also used pairs to see if the player's name is mentioned on the array on line 1.

for _,array in pairs(table) do
end

This is it finished.

admins={"iKxtiee","jtefurd","Player","Player1", "LordDragonZord"}
game.Players.PlayerAdded:connect(function(plyr)--When a player joins
    plyr.Chatted:connect(function(msg) --If that player talks:
       if msg == ":regenblocks" then --and says this:
    for _,adminplayers in pairs(admins) do --If their name is on the array on line 1.
        if plyr.Name == adminplayers then
        game.Workspace.Blocks:Destroy()     --Do this.
            local blocks=game.Lighting.Blocks:Clone()
           blocks.Parent=game.Workspace
    for _,v in pairs(blocks:GetChildren()) do
       for i=1,0,-.01 do
           v.Transparency=i
           wait(.05)
        end
    end     
        end
    end
           print("Blocks have regenerated! :)") --Print.
       end
    end)
end)
Ad
Log in to vote
-1
Answered by
yoshiegg6 176
9 years ago

You used "game.Players.admins" but there won't always be an admin in game, it doesn't work that way. Also you didn't add an extra parentheses in your connection. Try this.

Edit: This is the fixed version.

admins={"iKxtiee","jtefurd","Player","Player1"}

game.Players.PlayerAdded:connect(function(Player) --Fixed
Player.Chatted:connect(function(msg)
for i,n inpairs(admins) do --Have to iterate over admins to check if its the player
if Player.name = n and msg == ":regenblocks" then --If their name is in the admin table and they say regebblocks then
        game.Workspace.Blocks:Destroy()     
        local blocks=game.Lighting.Blocks:Clone()
        blocks.Parent=game.Workspace
for _,v in pairs(blocks:GetChildren()) do
    for i=1,0,-.01 do
        v.Transparency=i
        wait(.05)
    end
end     
        print("Blocks have regenerated! :)")
    end)
end)

0
I found a few syntax errors, but corrected them. Anyhow there are no errors in the output, yet the function still isn't executing. Thanks for help though. jtefurd 50 — 9y
0
The players service does not have a Chatted event. BlueTaslem 18071 — 9y
0
Oh, I didn't see that either. jtefurd 50 — 9y
0
Oh, sorry. Let me fix that. yoshiegg6 176 — 9y
0
Is it good now? Please upvote. yoshiegg6 176 — 9y

Answer this question