Help Needed on Bus Mechanic!

This is a very basic problem. I am currently developing a game like Camping. I am making an entering bus mechanic and exiting bus mechanic. I have completed the mechanic. It was a basic CFrame and Vector3 incorporation.

-Enter Bus: The script is a server script. Once a player step on a designated area, a gui tweens onto screen.

-Gui(Issue): Once it’s clicked, it respawns the character and tweens back.

Once the player tries stepping on the designated area once more, the gui doesn’t tween on screen. I have used ‘if then’ statements but nothing seems to be working. The goal of the script is to make the gui appear everytime the player steps on the designated area.

2 Likes

Please provide the code that opens and closes the GUI, also check if the ResetOnSpawn property of the ScreenGui is set to true.

Touched Script:

local part = script.Parent
local exitgui = script.Parent[“RespawnGui”]

part.Touched:connect(function(hit)
if hit and hit.Parent:findFirstChild(“Humanoid”) then
local plr = game:GetService(“Players”):GetPlayerFromCharacter(hit.Parent)
if not plr:WaitForChild(“PlayerGui”):findFirstChild(“RespawnGui”) then
exitgui:Clone().Parent = plr.PlayerGui
exitgui.Frame:TweenPosition(UDim2.new(0, 373,0, 89))
elseif
exitgui.Frame.Position == {0.363, 0,5, 0} then
exitgui.Frame:TweenPosition(UDim2.new(0, 373,0, 89))
end
end
wait()
end)


GUI Script:

local plr = game:GetService(“Players”).LocalPlayer

local spawns = workspace.SpawnLocation

script.Parent.MouseButton1Click:Connect(function()

plr.Character.HumanoidRootPart.CFrame = spawns.CFrame + Vector3.new(0,5,0)

script.Parent.Parent:TweenPosition(UDim2.new(0.363, 0,5, 0))

print(“Fired”)

end)

The property is set to true. Is it the fact that it’s a local script? I can do :LoadCharacter with a server script, however, I want to do it locally.

1 Like

Formatted

local part = script.Parent
local exitgui = script.Parent[“RespawnGui”]

part.Touched:connect(function(hit)
    if hit and hit.Parent:findFirstChild(“Humanoid”) then
        local plr = game:GetService(“Players”):GetPlayerFromCharacter(hit.Parent)
            if not plr:WaitForChild(“PlayerGui”):findFirstChild(“RespawnGui”) then
                exitgui:Clone().Parent = plr.PlayerGui
                exitgui.Frame:TweenPosition(UDim2.new(0, 373,0, 89))
            elseif exitgui.Frame.Position == {0.363, 0,5, 0} then
                exitgui.Frame:TweenPosition(UDim2.new(0, 373,0, 89))
            end
        end
    wait()
end)
local plr = game:GetService(“Players”).LocalPlayer
local spawns = workspace.SpawnLocation

script.Parent.MouseButton1Click:Connect(function()
    plr.Character.HumanoidRootPart.CFrame = spawns.CFrame + Vector3.new(0,5,0)
    script.Parent.Parent:TweenPosition(UDim2.new(0.363, 0,5, 0))
    print(“Fired”)
end)

If I’m understanding the issue properly, your exitgui is no longer a valid reference because the character would have already died by the time you use that. Turn off the ResetOnSpawn property and see if that solves your issue.

Another concern is formatting your code proeperly on the forum, please read this post on how to create code snippets/blocks on the forum.

I’m surprised the script didn’t work. I turned the property off, however, it won’t tween back on screen.

Hmm, sorry I missed some things, I haven’t gotten a lot of sleep.

I fixed up your code a bit:

ServerScript:

local PlayersService = game:GetService("Players")
local Part = script.Parent
local ExitScreen = script.Parent:WaitForChild("RespawnGui")

local function OnTouched(Hit)
    if Hit.Parent:FindFirstChild("Humanoid") then
        local Player = PlayersService:GetPlayerFromCharacter(Hit)
        if not Player:WaitForChild("PlayerGui"):FindFirstChild("RespawnGui") then
            ExitScreen:Clone().Parent = Player.PlayerGui
            ExitScreen.Frame:TweenPosition(UDim2.new(0, 373,0, 89))
        else
            exitgui.Frame:TweenPosition(UDim2.new(0, 373,0, 89))
        end
    end
end

Part.Touched:Connect(OnTouched)

The code still has the same result. I might just try a different approach.