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

CanCollide Not Changing When Player Chatted Message?

Asked by 4 years ago

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.

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". Geobloxia 251 — 4y
0
And do that for every single one. Geobloxia 251 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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.

0
Thank you! Explorer2021 22 — 4y
Ad

Answer this question