Hello Everyone, I asked this question before, but it was not answered clearly. I have a game that saves spawn points and you can choose whether to save at spawn points or a map. So I have this map called Battle Field, and I made two teams just in honor for that map! So everyone in the game is split into two teams already. Then after that, I have a click detector that onClick moves the Player into the Battle Field. The problem is it moves all players to a certain spot. Is there a way for me to add soemthign to the script for example defing the teams, and moving them to seperate areas inside of the Battle Field Map?
Well I’m assuming you already have a reference to the player from the button press.
From there, its really simple to check what team they are on.
local Player = (whatever the player is)
local PlayersTeam = Player.Team
if Player.Team = game.Teams.Red then
-- Teleport player to Red team position.
elseif Player.Team = game.Teams.Blue then
-- Teleport player to Blue team position.
end
If you need help implementing this, please share your code and I can explain further.
print("Hello world!")
local box = script.Parent
local player = game.Players.LocalPlayer
local function onClick(player)
player.Character:MoveTo(Vector3.new(-561.5, 68.254, -962.5))
end
box.ClickDetector.MouseClick:Connect(onClick)
---This is my code how would I add your code inside mine? Also are you sure the color for the teams will work because there are different shades of Red and Blue for example.
A efficient way to do this would be to set each team to a position in a dictionary and apply it.
Here is a demonstration. Doing it on the client side since physics replicate to the server but it would be better to do it in the server.
local Teams = game:GetService("Teams")
local player = game.Players.LocalPlayer
local dictionary = {
Red = blue_area_position;
Blue = red_area_position;
}
player.Character.Position = dictionary[Player.Team]
I don’t want to just give you the code straight away without you understanding it so i’ll go through it bit by bit.
local teams = game:GetService("Teams")
local teamToPosition = { -- Here's the dictionary that @SilentsReplacement talked about.
[Teams.Red] = Vector3.new(-100, 1, 0),
[Teams.Blue] = Vector3.new(100, 1, 0)
}
In your script you would replace Red and Blue with the names of your teams.
You would also replace the Vector3’s with the positions you want that team to move toward. (Vector3.new(-561.5, 68.254, -962.5))
Just to explain the Dictionary a bit:
-- If you were to say
teamToPosition[Teams.Red] -- This would give you Vector3.new(-100, 1, 0)
teamToPosition[Teams.Blue] -- This would give you Vector3.new(100, 1, 0)
So using this we can insert it into your script.
local box = script.Parent
local teamToPosition = {
[Teams.Red] = Vector3.new(-100, 1, 0), -- You would replace "Red" with the name of one of your teams
[Teams.Blue] = Vector3.new(100, 1, 0) -- And replace "Blue" with the name of the other.
}
local function onClick(player)
local Position = teamsToPosition[player.Team]
player.Character:MoveTo(Position)
end
box.ClickDetector.MouseClick:Connect(onClick)
local teams = game:GetService("Teams")
local box = script.Parent
local teamToPosition = {
[Teams.Green] = Vector3.new(-736.151, 64.281, -972.05), -- You would replace "Red" with the name of one of your teams
[Teams.Blue] = Vector3.new(-555.88, 64.281, -1124.69) -- And replace "Blue" with the name of the other.
}
local function onClick(player)
local Position = teamsToPosition[player.Team]
player.Character:MoveTo(Position)
end
box.ClickDetector.MouseClick:Connect(onClick)
You need to understand basic Lua before doing this. Youre issue is that youre variable name is wrong. Replace the word with the blue line under it with TeamToPosition.
local Teams = game:GetService("Teams")
local box = script.Parent
local TeamToPosition = {
[Teams.Green] = Vector3.new(-736.151, 64.281, -972.05), -- You would replace "Red" with the name of one of your teams
[Teams.Blue] = Vector3.new(-555.88, 64.281, -1124.69) -- And replace "Blue" with the name of the other.
}
local function onClick(player)
local Position = TeamsToPosition[player.Team]
player.Character:MoveTo(Position)
end
box.ClickDetector.MouseClick:Connect(onClick)
local Teams = game:GetService("Teams")
local box = script.Parent
local TeamToPosition = {
[Teams.Green] = Vector3.new(-736.151, 64.281, -972.05), -- You would replace "Red" with the name of one of your teams
[Teams.Blue] = Vector3.new(-555.88, 64.281, -1124.69) -- And replace "Blue" with the name of the other.
}
local function onClick(player)
local Position = TeamToPosition[player.Team]
player.Character:MoveTo(Position)
end
box.ClickDetector.MouseClick:Connect(onClick)