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

CanCollide Not Changing When Player Chatted Message?

Alright, so I'm trying to make a script that opens/closes a door depending on what the person says, and what rank in my group they are. Although I've tried to fix it, I just can't. Here's my code:

local staffRankId = 12
local groupId = 5947903

game:GetService("Players").PlayerAdded:Connect(function(plr)

	plr.Chatted:Connect(function(msg)
		if plr:GetRankInGroup(groupId) >= staffRankId then
			if msg =="/spawn" then
				game.Workspace.Spawn.CanCollide = false
			end
			if msg =="/cspawn" then
				game.Workspace.Spawn.CanCollide = true
			end
		end
	end)

Thanks in advance.

2 comments

0

This isn't the answer, but it's a tip. After "plr.Chatted:Connect(function(msg)" put "msg = string.lower(msg)" This makes sure that even though the player says the command with incorrect capitalization, the command will still execute (just make sure all the letters in the "if msg == """ are lowercase). An alternative but less efficient way is by doing: "if string.lower(msg) == "/spawn" then".

0

And do that for every single one.

1 answer

✓ Accepted answer

fix:

local staffRankId = 12
local groupId = 5947903

game:GetService("Players").PlayerAdded:Connect(function(plr)
    plr.Chatted:Connect(function(msg)
        if plr:GetRankInGroup(groupId) >= staffRankId then
            if msg =="/spawn" then
                game.Workspace.Spawn.CanCollide = false
            elseif msg =="/cspawn" then
                game.Workspace.Spawn.CanCollide = true
            end
        end
    end)
end)

You forgot end) on line after the other one. I'm also making your script shorter.

1 comment

0

Thank you!

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