UI When car hits an object wont pop up

There is no errors. For some reason it wont clone and show. I am trying to fix this
Here’s what this does, when the car touches a region/area it opens a UI or duplicates it.
This all runs from a SS.
Code:

local players = game:GetService('Players')
local storage = game:GetService('ServerStorage')

script.Parent.Touched:Connect(function(hit)
    if hit.Name == 'DriveSeat' then
        local child = hit.Parent:FindFirstChild('SeatWeld')
        print(hit.Name) -->> DriveSeat
    if hit:FindFirstChild("SeatWeld") then
            print(child)
            local fakePlayer = child.Part1.Parent:GetChildren()
            local realPlayer = players:GetPlayerFromCharacter(fakePlayer)
            local playerGui = realPlayer:WaitForChild('PlayerGui')
            print(realPlayer) -->> plr
            if not playerGui:FindFirstChild('CarPaint') then
                local gui = storage.CarPaint:Clone()
                gui.Parent = playerGui
            end
        end
    end
end)

If you can help, would mean alot. Thanks!

Did you make sure your GUI is enabled?

A note: It’s good practice to fire an event to the client and have the client work with the UI. Try putting the UI in ReplicatedStorage and having the client obtain it from there when the event is fired.

The GUI is enabled, and I’ll try firing.

Can you provide an image of the explorer for the player sitting in the car seat?

image
There you go. :slight_smile:

Shouldn’t this line be:

local child = hit:FindFirstChild('SeatWeld')

Because the weld is parented inside the seat?

Also, instead of checking for a weld you could use the property Seat.Occupant instead.
Code:

local players = game:GetService('Players')
local storage = game:GetService('ServerStorage')

script.Parent.Touched:Connect(function(hit)
    if hit.Name == 'DriveSeat' and hit.Occupant then
        local fakePlayer = hit.Occupant.Parent
        local realPlayer = players:GetPlayerFromCharacter(fakePlayer)
        if realPlayer then
            local playerGui = realPlayer:WaitForChild('PlayerGui')
            if not playerGui:FindFirstChild('CarPaint') then
                local gui = storage.CarPaint:Clone()
                gui.Parent = playerGui
            end
        end
    end
end)

(Untested).

2 Likes

Okay! Testing right now. Thanks for the help.

In that case, why wait for the server to fire another event when Touched is fired? Just listen to the Touched event instead.

2 Likes