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?
A CanCollide Command?
1 answer
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)
4 comments
What If I only wants myself to say it
Thank you sir! I promise I won't ask these nonsense question
Wait is this LocalScript or Script? because it don't seem to work?
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
This discussion is preserved as it was. New answers, comments, and votes are closed.

6 comments
Not a request site. I can give you an idea on how to do it...
Yes pls I'm really sorry
Edited it.
Can you please accept my answer?
I can't I have -1
Make it a regular script.