I’m having issues on attempting to either teleport or on checking the player’s team and im not quite sure I know what the problem is. This is a Localscript inside of a Guibutton for teleporting and changing the camera. I’m currently attempting this : Checking if the BoolValues (ConB , ConR , Contested) are true or not and via that determening wether or not the function fires if the player presses script.parent .
Camera change works, but teleportation doesnt work, ive tried using TeamColor instead of the team name but that didn’t work. I tried incorporating checks into the function itself instead of outside it, that didn’t work.
Please help.
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local team = player.TeamColor.Name
local ConB = game.Workspace.PointAs.Zone.ConB.Value
local ConR = game.Workspace.PointAs.Zone.ConR.Value
local Contested = game.Workspace.PointAs.Zone.Contested.Value
script.Parent.MouseEnter:Connect(function()
game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
game.Workspace.CurrentCamera.CFrame = game.Workspace.PointAs.SPAWN.CFrame
end)
if team == "Red" and ConR then
mouse.Button1Down:Connect(function()
if mouse.Target == script.Parent then
game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
player.Character.HumanoidRootPart.CFrame = game.Workspace.PointAs.SPAWN.CFrame
script.Parent.Parent.Enabled = false
end
end)
elseif team == "Blue" and ConB then
mouse.Button1Down:Connect(function()
if mouse.Target == script.Parent then
game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
player.Character.HumanoidRootPart.CFrame = game.Workspace.PointAs.SPAWN.CFrame
script.Parent.Parent.Enabled = false
end
end)
end
if Contested then
script.Parent.BackgroundColor3 = Color3.new(0.564706, 0.564706, 0.564706)
end
Instead of using mouse click you can use a image button or label button instead.
also you should check the team IN the connect function
Example:
mouse.Button1Down:Connect(function()
if team == "Red" and ConR then
--Red team code stuff
elseif team == "Blue" and ConB then
--Blue team code stuff
end
end)
I did change it now, also changed the TeamColor names. Still won’t work, do I have to constantly update the status of the BoolValues? Do I have to use a remoteevent for this? I don’t know anymore
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local team = player.TeamColor.Name
local ConB = game.Workspace.PointAs.Zone.ConB.Value
local ConR = game.Workspace.PointAs.Zone.ConR.Value
local Contested = game.Workspace.PointAs.Zone.Contested.Value
script.Parent.MouseEnter:Connect(function()
game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
game.Workspace.CurrentCamera.CFrame = game.Workspace.PointAs.SPAWN.CFrame
end)
mouse.Button1Down:Connect(function()
if team == "Maroon" and ConR then
if mouse.Target == script.Parent then
game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
player.Character.HumanoidRootPart.CFrame = game.Workspace.PointAs.SPAWN.CFrame
script.Parent.Parent.Enabled = false
elseif
team == "Bright blue" and ConB then
if mouse.Target == script.Parent then
game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
player.Character.HumanoidRootPart.CFrame = game.Workspace.PointAs.SPAWN.CFrame
script.Parent.Parent.Enabled = false
end
end
end
if Contested then
script.Parent.BackgroundColor3 = Color3.new(0.564706, 0.564706, 0.564706)
end
end)
It seems that the issue lies in the placement and execution of your code. The code you have written is executed only once when the LocalScript is initially run, and not continuously as you may expect. To fix this issue, you need to move the code inside the event handlers so that it is executed when the button is pressed. Here’s an updated version of your LocalScript:
lua
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local team = player.TeamColor.Name
script.Parent.MouseEnter:Connect(function()
game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
game.Workspace.CurrentCamera.CFrame = game.Workspace.PointAs.SPAWN.CFrame
end)
script.Parent.MouseButton1Down:Connect(function()
if team == "Red" and game.Workspace.PointAs.Zone.ConR.Value then
if mouse.Target == script.Parent then
game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
player.Character.HumanoidRootPart.CFrame = game.Workspace.PointAs.SPAWN.CFrame
script.Parent.Parent.Enabled = false
end
elseif team == "Blue" and game.Workspace.PointAs.Zone.ConB.Value then
if mouse.Target == script.Parent then
game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
player.Character.HumanoidRootPart.CFrame = game.Workspace.PointAs.SPAWN.CFrame
script.Parent.Parent.Enabled = false
end
end
end)
if game.Workspace.PointAs.Zone.Contested.Value then
script.Parent.BackgroundColor3 = Color3.new(0.564706, 0.564706, 0.564706)
end
In this updated script, the code inside the event handlers will be executed when the button is pressed. Additionally, the values of ConB, ConR, and Contested are accessed directly from game.Workspace.PointAs.Zone instead of being stored in separate variables. Make sure to place this LocalScript inside a LocalScript container (not a Script or a ModuleScript) within the GuiButton. This will ensure that the event handlers are properly connected to the button’s events. Please give this updated script a try and see if it resolves the teleportation issue you were facing.