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

A CanCollide Command? [closed]

Asked by 9 years ago

Hi there, I wanted to make a command that if i say "/lockspawn" the part CanCollide but when i say "/unlockspawn" the part UnCanCollide. I don't have the script anymore because I deleted it. Any Idea how to make the script?

0
Not a request site. I can give you an idea on how to do it... EzraNehemiah_TF2 3552 — 9y
0
Yes pls I'm really sorry CjGamer1454 0 — 9y
0
Edited it. EzraNehemiah_TF2 3552 — 9y
0
Can you please accept my answer? EzraNehemiah_TF2 3552 — 9y
View all comments (2 more)
0
I can't I have -1 CjGamer1454 0 — 9y
0
Make it a regular script. EzraNehemiah_TF2 3552 — 9y

Locked by EzraNehemiah_TF2 and M39a9am3R

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

1 answer

Log in to vote
0
Answered by 9 years ago

First, use string.sub() to get the substring of the msg that the player has chatted using the player event.


Get the player by using PlayerAdded. You must do this in a regular script. You can use Local scripts for this but the local script would get copied and there would have to be 1 local script per player instead of just 1 script for the whole server.

game:GetService("PlayerAdded"):connect(function(player)
    print(player.Name) --Get the player's name.
end)

See if they have chatted using the chatted event.

game:GetService("PlayerAdded"):connect(function(player)
    player.Chatted:connect(function(chat)
        if string.sub(chat, 1,8) == "/unlock " and workspace:FindFirstChild(string.sub(chat,9)) then
            workspace:FindFirstChild(string.sub(chat,9)).CanCollide = false
        elseif string.sub(chat, 1,5) == "/lock " and workspace:FindFirstChild(string.sub(chat,6)) then
            workspace:FindFirstChild(string.sub(chat,6)).CanCollide = true
        end
    end)
end)

Or you can do this to just lock the spawn.

game:GetService("PlayerAdded"):connect(function(player)
    player.Chatted:connect(function(chat)
        if string.sub(chat, 1,12) == "/unlockspawn" then
            workspace.Spawn.CanCollide = false
        elseif string.sub(chat, 1,5) == "/lockspawn" then
            workspace.Spawn.CanCollide = true
        end
    end)
end)


If you want to do this in a script:

function lock(part)
    part.CanCollide = true
end

function unlock(part)
    part.CanCollide = false
end

lock(game.Workspace.Part)
unlock(game.Workspace.Part2)



Hope it helps!





If you only want some people to say it:

admin = {"LordDragonZord", "Player1"} --Add your name here. Add as much people as you'd like.

game:GetService("PlayerAdded"):connect(function(player)
    player.Chatted:connect(function(chat)
        for _,AdminName in pairs(admin) do
            if player.Name == AdminName then
                if string.sub(chat, 1,8) == "/unlock " and workspace:FindFirstChild(string.sub(chat,9)) then
                    workspace:FindFirstChild(string.sub(chat,9)).CanCollide = false
                elseif string.sub(chat, 1,6) == "/lock " and workspace:FindFirstChild(string.sub(chat,7)) then
                    workspace:FindFirstChild(string.sub(chat,6)).CanCollide = true
                end
            end
        end
    end)
end)

Or...

admin = {"LordDragonZord", "Player1"} --Add your name here. Add as much people as you'd like.

game:GetService("PlayerAdded"):connect(function(player)
    player.Chatted:connect(function(chat)
        for _,AdminName in pairs(admin) do
            if player.Name == AdminName then
                if string.sub(chat, 1,12) == "/unlockspawn" then
                    workspace.Spawn.CanCollide = false
                elseif string.sub(chat, 1,5) == "/lockspawn" then
                    workspace.Spawn.CanCollide = true
                end
            end
        end
    end)
end)
0
What If I only wants myself to say it CjGamer1454 0 — 9y
0
Thank you sir! I promise I won't ask these nonsense question CjGamer1454 0 — 9y
0
Wait is this LocalScript or Script? because it don't seem to work? CjGamer1454 0 — 9y
0
On line 9 of the fifth code; You are comparing ':sub' to a string that is '10' characters long, when sub is getting 1-5 characters of the string. :P TheeDeathCaster 2368 — 9y
Ad