This script is inside a GUI button. The point is to teleport the player to a random part inside a model in the workspace called "Map" based on the player's team. I don't want to use normal spawnlocations (so when the player dies they go back to the lobby and have to click play again), just blocks labeled 1-8 inside of the model "Team1" or "Team2." I have tried to find the problem but I have no clue whats wrong.
Script:
local player = script.Parent.Parent.Parent.Parent.Parent
--- locate the name of the team
local team = script.Parent.Parent.Parent.Parent.Parent.Team
--- locate the model with the same name as the team inside the map
local s = game.Workspace.Map:FindFirstChild(""..team)
--- choose random part (labeled 1-8) in model
tspawn = s:GetChildren()[math.random(#model:GetChildren())]
--- here on is if player click then player teleported to the random block
script.Parent.MouseButton1Click:connect(function()
player.Character:MoveTo(tspawn.Position)
end
end
Any Idea whats wrong?
|