When I made the “team door” I ran into a problem, a player from team 2 can walk through the door too when player form team1 opens it
Example: https://streamable.com/cvq2it
Code:
debounce = false
script.Parent.Touched:connect(function(lolteamdoorsgoesprr)
if (lolteamdoorsgoesprr) then
if (lolteamdoorsgoesprr.Parent) then
a = game:GetService("Players"):GetPlayerFromCharacter(lolteamdoorsgoesprr.Parent)
if (a) then
if (a.TeamColor == BrickColor.new("Really red")) then
debounce = true
script.Parent.Transparency = 0.5
script.Parent.CanCollide = false
wait(3)
script.Parent.Transparency = 0
script.Parent.CanCollide = true
debounce = false
end
end
end
end
end)
I thinking about kill other teams on touch, but that’s not what i exactly want to do.
I want to make it thanks to serverstorage but i dont know exactly how
Couldn’t you just set the Character’s Position a couple studs back from where the door is if they’re not the same team color?
debounce = false
local DeniedPosition = Vector3.new(0, 0, 0) --Set this to where you want to TP the player back
script.Parent.Touched:connect(function(lolteamdoorsgoesprr)
if (lolteamdoorsgoesprr) then
if (lolteamdoorsgoesprr.Parent) then
a = game:GetService("Players"):GetPlayerFromCharacter(lolteamdoorsgoesprr.Parent)
if (a) then
if (a.TeamColor == BrickColor.new("Really red")) then
debounce = true
script.Parent.Transparency = 0.5
script.Parent.CanCollide = false
wait(3)
script.Parent.Transparency = 0
script.Parent.CanCollide = true
debounce = false
else
lolteamdoorsgoesprr.Parent.HumanoidRootPart.Position = DeniedPosition
end
end
end
end
end)
debounce = false
script.Parent.Touched:connect(function(lolteamdoorsgoesprr)
if (lolteamdoorsgoesprr) then
if (lolteamdoorsgoesprr.Parent) then
a = game:GetService("Players"):GetPlayerFromCharacter(lolteamdoorsgoesprr.Parent)
if (a) then
if (a.TeamColor == BrickColor.new("Really red")) then
debounce = true
game.ReplicatedStorage.RemoteEvent:FireClient(script.Parent)
wait(3)
debounce = false
end
end
end
end
end)
Then on the client you can change the transparency and collision.
The simplest fix from what every has been saying is to put a script like this in StarterPlayerScripts
debounce = false
loacl plrs = game:GetService("Players")
local localplr = plrs.LocalPlayer
local allowedColor = BrickColor.new("Really Red")
script.Parent.Touched:connect(function(hit)
local plr = plrs:GetPlayerFromCharacter(hit.Parent)
local color = plr and plr.TeamColor
if not plr or plr ~= localplr or color ~= allowedColor then return end
debounce = true
script.Parent.Transparency = 0.5
script.Parent.CanCollide = false
wait(3)
script.Parent.Transparency = 0
script.Parent.CanCollide = true
debounce = false
end)
Let’s pretend RemoteEvents didn’t exist for a moment ¯_(ツ)_/¯
@krrtek Also from what everyone has said, you can use those to change/detect stuff from the server side to the client side, if you want you can look up the API Reference for this to have a better understanding:
Here’s a more fixed up version of the solution that you could use, the method I used will move the player back 5 studs if they are not on the team
local plrDebs = {}
local debounce = false
local door = script.Parent
door.Touched:Connect(function(hit)
local char = hit.Parent
local plr = game:GetService("Players"):GetPlayerFromCharacter(char)
if not plr or plrDebs[plr.Name] then return end
local root = char:FindFirstChild("HumanoidRootPart") or char.Parent:FindFirstChild("HumanoidRootPart")
local color = plr.TeamColor
if color == BrickColor.new("Really red") then
if debounce then return end
debounce = true
door.Transparency = 0.5
door.CanCollide = false
wait(3)
door.Transparency = 0
door.CanCollide = true
debounce = false
else
plrDebs[plr.Name] = true
root.CFrame += door.CFrame.LookVector * 5
wait(0.5)
plrDebs[plr.Name] = nil
end
end)
You will have to change the LookVector to RightVector if the teleport location is off, or do -5 instead of 5. Also no one was using the debounce variable correctly so I added a fix to that
Edit: Changed connect to Connect as the former is deprecated and changed all the script.Parent to door