I have been working on a game and I wanted a part where players on one team can walk over a block while players on another team fall through it. I was going to make it so that if a player from the team I want to be able to stand touched it the script would set "can collide" to true and when they weren't on it "can collide" would be set to off. However this would mean that if that player was on the block then the other team would be able to cross it until they got off. this would create problems and make things too easy. I don't even know if it is possible to even make a script like that. I tried plugging a few promising script parts into the end of this one:
script.Parent.Touched:connect(function(hit)
local Player = game.Players:GetPlayerFromCharacter(hit.Parent) if Player and Player.TeamColor == BrickColor.new("team color") then
(script end) to try and get the results I wanted to no avail. I had even tried the free models section. Now i'm at my ropes end, so I came here to ask for help.
this script will make Pearl team color go through. while black team color it turns it back so they cant
script.Parent.Touched:connect(function(hit) local Player = game.Players:GetPlayerFromCharacter(hit.Parent) if Player and Player.TeamColor == BrickColor.new("Pearl") then script.Parent.CanCollide = false elseif Player and Player.TeamColor == BrickColor.new("Black") then script.Parent.CanCollide = true end end)
Local parts are parts that are only client sided, meaning that the server can't interact with it and everyone else cannot see it.
To make local parts you just need to turn on Filtering Enabled which is a property of the workspace datamodel. This will stop client-sided code from changing the server. So if we turn FE on and insert a part into workspace, only the player with that local script is able to see it.
--Local Script if game:GetService("Players").LocalPlayer.Name == "Player1" then local part = Instance.new("Part",workspace) --Adds a part to workspace end if workspace:FindFirstChild("Part") then print("Part exists") --Print if the part is findable else print("Part doesn't exist") --Print if the part is nonexistent. end
Part exists
--Every server-sided script and other player's local script if workspace:FindFirstChild("Part") then print("Part exists") --Print if the part is findable else print("Part doesn't exist") --Print if the part is nonexistent. end
Part doesn't exist
So in this experiment, only the person named "Player1" can see that part. Everyone else and all the server scripts cannot, because the part only exists on that computer and that computer only.
Local Script. The way I do it, you don't need to worry about GetPlayerFromCharacter
erroring if a rogue part accidently touches it and either blocks all the players or lets all the players in. If you do it all server-sided, you can actually sneak passed the brick as long as someone else on the other team touches it after you touch it. Basically it's error free! MAKE SURE FILTERING ENABLED IS... well, enabled.
local part = Instance.new("Part", workspace) --Part is inside of workspace part.BrickColor = BrickColor.new(...) --Change all the "..."s to any value you want! part.Size = Vector3.new(...) part.CFrame = CFrame.new(...) --The position part.Name = ... local player = game:GetService("Players").LocalPlayer --The player if player.TeamColor == BrickColor.new("Bright red") or player.TeamColor == BrickColor.Green() then --If they're a bright red color OR if they're BrickColor.Green (Bright green) then... (you can add more "or"s) part.CanCollide = false --Let them walk through else --If they're any other color then... You can do "elseif" to add another if then statement. part.CanCollide = true --Block the enemy players! end
If you put this inside of starter player scripts then it'll make a new part for everyone so everyone can see the part, only some people can pass through.
Hope it helps!