Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I make a block that holds one team and not the other(s)?

Asked by 8 years ago

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)

1local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
2 
3if 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.

2 answers

Log in to vote
0
Answered by 8 years ago
Edited 8 years ago

this script will make Pearl team color go through. while black team color it turns it back so they cant

01script.Parent.Touched:connect(function(hit)
02 
03local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
04 
05if Player and Player.TeamColor == BrickColor.new("Pearl") then
06 
07    script.Parent.CanCollide = false
08elseif Player and Player.TeamColor == BrickColor.new("Black") then
09    script.Parent.CanCollide = true
10 
11 
12end
13end)
0
What if 2 people on both teams go in at the same time. The script won't work then because both of them can't go through! EzraNehemiah_TF2 3552 — 8y
0
If some random block that isn't the player touches it then it won't work either! hit.Parent if it's a part in workspace will give you the workspace datamodel, which isn't a character and will error. EzraNehemiah_TF2 3552 — 8y
Ad
Log in to vote
0
Answered by 8 years ago
Edited 8 years ago

Better solution

Local parts are parts that are only client sided, meaning that the server can't interact with it and everyone else cannot see it.


Local parts

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.

01--Local Script
02if game:GetService("Players").LocalPlayer.Name == "Player1" then
03    local part = Instance.new("Part",workspace) --Adds a part to workspace
04end
05 
06if workspace:FindFirstChild("Part") then
07    print("Part exists") --Print if the part is findable
08else
09    print("Part doesn't exist") --Print if the part is nonexistent.
10end

Part exists

1--Every server-sided script and other player's local script
2if workspace:FindFirstChild("Part") then
3    print("Part exists") --Print if the part is findable
4else
5    print("Part doesn't exist") --Print if the part is nonexistent.
6end

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.


Final Product

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.

01local part = Instance.new("Part", workspace) --Part is inside of workspace
02part.BrickColor = BrickColor.new(...) --Change all the "..."s to any value you want!
03part.Size = Vector3.new(...)
04part.CFrame = CFrame.new(...) --The position
05part.Name = ...
06local player = game:GetService("Players").LocalPlayer --The player
07 
08if 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)
09    part.CanCollide = false --Let them walk through
10else --If they're any other color then... You can do "elseif" to add another if then statement.
11    part.CanCollide = true --Block the enemy players!
12end

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!

Answer this question