Local script - Can Collide

image

local Prisoners = "Prisoners" --Whatever name of the prisoner team is.
Teams = game:GetService("Teams")

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChildOfClass("Humanoid") then --To check if it is a player
		local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if Player.Team == Teams[Prisoners] then --Check the original team
			script.Parent.CanCollide = false
		else
			script.Parent.CanCollide = true
		end
	end
end)

I need a local script that will allow players from the Prisoners team to pass but not everyone else. But for some reason this does not work.

Local Scripts only works if the script is in the Player or ReplicatedFirstService

You can create another script to change the LocalScript.Parent to the player

Can I make CanCollide local? Or how do I do it?

yes, you can.

I put this script in the StarterPlayer

local part = workspace.part

part.CanCollide = false

this is just an example, you dont need to use the Touched event cause your using a local script already, so it doesn’t matter

1 Like

Right? image

put it in the StarterPlayerScripts

1 Like
local part = workspace.antiSPAWNKILL
local Prisoners = "Prisoners" --Whatever name of the prisoner team is.
Teams = game:GetService("Teams")

part.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChildOfClass("Humanoid") then --To check if it is a player
		local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if Player.Team == Teams[Prisoners] then --Check the original team
			part.CanCollide = true
		else
			part.CanCollide = false
		end
	end
end)

it isn’t works

I can’t write local scripts. Can you help?

if you want only the prisoners to pass. do this:

if Player.Team == Teams[Prisoners] then --Check the original team
			part.CanCollide = false
		else
			part.CanCollide = true
		end

you mixed up the CanCollide

local part1 = workspace.antiSPAWNKILL
local humanoid = part1:FindFirstChild("Humanoid") 
local Prisoners = "Prisoners" --Whatever name of the prisoner team is.
Teams = game:GetService("Teams")

part1.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChildOfClass("Humanoid") then --To check if it is a player
		local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if Player.Team == Teams[Prisoners] then --Check the original team
			part1.CanCollide = false
		else
			part1.CanCollide = true
			humanoid.Health = humanoid.Health - 10
		end
	end
end)

Why it isn’t damaging?