I am making a story-like game, and I have a leave button that teleports the player to spawn after they enter the vehicle. In test mode, the first time I sit the button pops up and works. The second time I sit, it doesn’t pop up. I don’t know why.
I’ve tried searching up my answer on Google, but that didn’t work.
This is code for the script to teleport the player to spawn after they trigger a function with the leave button:
local spawnTeleport = game.Workspace.SpawnTeleport
local EM = game.ReplicatedStorage.EnableMovement
local TTS = game.ReplicatedStorage.TeleportToSpawn
TTS.OnServerEvent:Connect(function(player)
local character = player.Character
local humanoid = character:FindFirstChild("Humanoid")
local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
humanoid.Jump = true
wait(0.10)
humanoidRootPart.Position = spawnTeleport.Position
print("Player teleported")
end)
EM.OnServerEvent:Connect(function(player)
local character = player.Character
local humanoid = character:FindFirstChild("Humanoid")
humanoid.WalkSpeed = 16
humanoid.UseJumpPower = true
humanoid.JumpPower = 50
print("Player can move")
end)
Is there code that stops showing the Leave Button? Also you probably shouldn’t create 3 different connections to the teleporter touch event, one will do.
local teleporter = script.Parent
local teleportPosition = game.Workspace.Part2.Position
function onTouched(otherPart)
character = otherPart.Parent
local humanoid = character:FindFirstChild("Humanoid")
local hrp = character:FindFirstChild("HumanoidRootPart")
if (hrp ~= nil) then
hrp.Position = teleportPosition
humanoid = character:FindFirstChild("Humanoid")
if (humanoid ~= nil) then
humanoid.WalkSpeed = 0
humanoid.UseJumpPower = true
humanoid.JumpPower = 0
end
wait(0.10)
local player = game.Players:GetPlayerFromCharacter(character)
player.PlayerGui.LeaveSystem.LeaveButton.Visible = true
end
end
teleporter.Touched:Connect(onTouched)
Yes, from the local script. When the player clicks the button from the local script, it disappears and fires the RemoteEvents that the script that I showed is listening for.
This is the local script that fires the events to put the player back at spawn and makes the button disappear
local button = script.Parent
local player = game.Players.LocalPlayer
local EM = game.ReplicatedStorage.EnableMovement
local TTS = game.ReplicatedStorage.TeleportToSpawn
button.MouseButton1Click:Connect(function()
button.Visible = false
print("Buttons gone")
EM:FireServer()
TTS:FireServer()
print("Events fired")
end)
So your probably running into a server/client replication issue. If your hiding the button on the client side. If you try to make it visible again on the server, then it will still be invisible on the client.
As explained, your issue is a server-client replication one, a GuiObject is being made visible by the server and subsequently invisible by the client. When the client performs this change it doesn’t replicate to the server, from the server’s perspective the GuiObject is still visible so when the server attempts to make the GuiObject visible again nothing happens. You need to shift the gui displaying/hiding to be performed solely by the client (such that replication issues don’t arise).