Team Doors thanks to serverstorage

Hello again Developers!

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

Thanks for your time
Krrtek

1 Like

Make the change on the Client side not server side.

Use remote events to fire the client.

Make the script client sided by making it a localscript in StarterCharacterScripts and doing some touch verification

IGNORING THE LOCAL STANDPOINT POSTS

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)

thanks!
3:0 c:h:a:r:s lol da xd

1 Like

Easily exploitable. Always do things like these on the server.

@EmbatTheHybrid @GoteeSign @caviarbro Keeping in mind he explicity said ServerStorage

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

Use CollisionGroups, these allow certain parts to clip- and others to pass right through