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

Help with custom command script?

Asked by
sad_eyez 162
7 years ago
Edited 7 years ago

Okay, So I scripted this custom command script for my friends building game to open then door of 1 of the boxes, and I tested it in studio and the actual game on my test place, but when I insert in his it won't work, so is it my script or is my script colliding with one of his, I really don't think it's my script though. If it isn't maybe someone can tell me what type of script it could be colliding with. Heres my code:

This is the admin part:

local admins = {"Player1", "ConsideredThought", "Architectix"}
game.Players.PlayerAdded:connect(function(plr)
    plr.Chatted:connect(function(msg)
        local prefix = ":"
        for i,a in pairs(admins) do
        if plr.Name == a then
            -------------------------------------------
            if msg == prefix.."open1" then
                module = require(script.DoorController)
                module.open1()
            elseif msg == prefix.."close1" then
                module.close1()
            end
        end
        end
    end)
end)

This is the command function:

function module.open1()
    local box = game.Workspace:WaitForChild("Box#1")
    for i,v in pairs(box:GetChildren()) do
        if v.Name == "Door" then
            if v.Transparency == 1 then
                return
            end
            for i = 4,0,-1 do
            v.Transparency = v.Transparency +0.1
            wait(0.1)
            end
            v.CanCollide = false
        end
    end
end

function module.close1()
    local box = game.Workspace:WaitForChild("Box#1")
    for i,v in pairs(box:GetChildren()) do
        if v.Name == "Door" then
            if v.Transparency == 0.6 then
                return
            end
            for i = 4,0,-1 do
            v.Transparency = v.Transparency -0.1
            wait(0.1)
            end
            v.CanCollide = true
        end
    end
end

1 answer

Log in to vote
1
Answered by
1N0body 206 Moderation Voter
7 years ago
Edited 7 years ago

If the "command function" is a module script then you need to insert 2 things:

local module = {} -- Declare table
function module.open1()
    local box = game.Workspace:WaitForChild("Box#1")
    for i,v in pairs(box:GetChildren()) do
        if v.Name == "Door" then
            if v.Transparency == 1 then
                return
            end
            for i = 4,0,-1 do
            v.Transparency = v.Transparency +0.1
            wait(0.1)
            end
            v.CanCollide = false
        end
    end
end

function module.close1()
    local box = game.Workspace:WaitForChild("Box#1")
    for i,v in pairs(box:GetChildren()) do
        if v.Name == "Door" then
            if v.Transparency == 0.6 then
                return
            end
            for i = 4,0,-1 do
            v.Transparency = v.Transparency -0.1
            wait(0.1)
            end
            v.CanCollide = true
        end
    end
end
return module -- return the module table when called.

Other than this, I see no problems. Hope I helped.

0
I already have that in the module script, I was just showing the function in between those lines sad_eyez 162 — 7y
Ad

Answer this question