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

this script is supposed to change a map, it doesn't error but it doesn't work. whats wrong?

Asked by 9 years ago
--------------------------------------------
--        Original Creator Is Not Me      --
--    But I Kinda Changed The Whole Thing --
--        Put The Script In The Map       --
--           Change This Script           --
--------------------------------------------

Permission = {"andrewboy159","PLAYER","PLAYER"} -- Players who can run the map.
RunText = "/computer run obby2" -- Text the Players have to say to run the map.
StopText = "/computer stop obby2" -- Text the Players have to say to stop the map.
Map = "Obby2" -- The name of the map in ServerStorage.


game.Players.ChildAdded:connect(function(Player)
Player.Chatted:connect(function(Chat)
local function OnChatted()

for i = 1, #Permission do
if Player.Name == Permission[i] then

if string.lower(Chat) == RunText then
if not game.Workspace:FindFirstChild("Obby2") then
game.ServerStorage.Obby2:Clone().Parent = game.Workspace
elseif string.lower(Chat) == StopText then

if game.Workspace:FindFirstChild(Map) then
game.Workspace[Map]:Remove()
end

game.Players.PlayerAdded:connect(function(Player)
    Player.Chatted:connect(function(Chat) local onChatted(Chat, Player) end)
end)
end
end
end
end
end
end)
end)

1 answer

Log in to vote
0
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
9 years ago

First, let's put your code in a code block and tab it correctly. This is a great example of why all code should always be tabbed right, for it makes the errors far clearer.

Permission = {"andrewboy159","PLAYER","PLAYER"} -- Players who can run the map.
RunText = "/computer run obby2" -- Text the Players have to say to run the map.
StopText = "/computer stop obby2" -- Text the Players have to say to stop the map.
Map = "Obby2" -- The name of the map in ServerStorage.


game.Players.ChildAdded:connect(function(Player)
    Player.Chatted:connect(function(Chat)
        local function OnChatted()

            for i = 1, #Permission do
                if Player.Name == Permission[i] then

                    if string.lower(Chat) == RunText then
                        if not game.Workspace:FindFirstChild("Obby2") then
                            game.ServerStorage.Obby2:Clone().Parent = game.Workspace
                        elseif string.lower(Chat) == StopText then

                            if game.Workspace:FindFirstChild(Map) then
                                game.Workspace[Map]:Remove()
                            end

                            game.Players.PlayerAdded:connect(function(Player)
                                Player.Chatted:connect(function(Chat) 
                                    local onChatted(Chat, Player) 
                                end)
                            end)

                        end
                    end
                end
            end
        end
    end)
end)

Now that it's all spaced out, see the problem? Your ends are completely placed oddly and incorrectly! For example, this is what I think you want:

if string.lower(Chat) == RunText then
    --do something
elseif string.lower(Chat) == StopText then
    --do something
end

But the way you place the ends, you're actually telling the computer to do this!

if not game.Workspace:FindFirstChild("Obby2") then
    --do something
elseif string.lower(Chat) == StopText then
    --do something
end

This is not the only problem. First of all, you should use the PlayerAdded event instead of ChildAdded. Second, why the function inside of the Chatted event? You already have the event connected in an anonymous function, you don't really need more than one connection. And why the PlayerAdded event inside the ChildAdded event? It's just weird, and won't work right.

I recommend taking on some smaller projects to try to better learn how to place ends and if statements. This code needs to be almost completely rewritten, and I don't think you understand enough of the basic concepts necessary to making an effective change-map-on-chat script. If you're completely set on this, however, try taking a look at this script I made for my group. Although more complex than what you're trying to do, you may be able to learn from some of the basic concepts and methods explored in the code.

0
thx for the advice, i got ur script i haven't tested it though andrewboy159 18 — 9y
Ad

Answer this question