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

How do I make a touch detector that only works for one team that opens a gate?

So I am trying to make a script that allows the player to open the gate if the are on the correct team I tried making the script myself but it didn't work. Here's the script:

of = script.Parent.onoff
db = false
if player.humanoid.team = NorthKorea---Doesn't work
script.Parent.Open.TouchDetector.Ontouch:connect(function()---Doesn't Work
if db == false then
if of.Value  == true then
db = true
for i = 0, 60, 1 do
script.Parent.Move.CFrame = script.Parent.Move.CFrame - Vector3.new(1.1,0,0)
wait(.05)
end
of.Value = false
end
db = false
end
end)
script.Parent.Close.ClickDetector.MouseClick:connect(function()
if db == false then
if of.Value  == false then
db = true
for i = 0, 60, 1 do
script.Parent.Move.CFrame = script.Parent.Move.CFrame - Vector3.new(-1.1,0,0)
wait(.05)
end
of.Value = true
end
db = false
end
end)

Please reply.

1 answer

✓ Accepted answer
of = script.Parent.onoff
db = false
script.Parent.Open.TouchDetector.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player.Team == "NorthKorea" then
if db == false then
if of.Value  == true then
db = true
for i = 0, 60, 1 do
script.Parent.Move.CFrame = script.Parent.Move.CFrame - Vector3.new(1.1,0,0)
wait(.05)
end
end
end
of.Value = false
end
db = false
end
end)
script.Parent.Close.ClickDetector.MouseClick:connect(function()
if db == false then
if of.Value  == false then
db = true
for i = 0, 60, 1 do
script.Parent.Move.CFrame = script.Parent.Move.CFrame - Vector3.new(-1.1,0,0)
wait(.05)
end
of.Value = true
end
db = false
end
end)

this gets the player from when the part is touched and checks its team

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