Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Help with custom command script?

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

✓ Accepted answer

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.

1 comment

0

I already have that in the module script, I was just showing the function in between those lines

This discussion is preserved as it was. New answers, comments, and votes are closed.