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?
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)
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?