Car spawner Gui broken

Hello, my script here does not seem to be working. What I want is that when the textbutton is clicked I want the car to spawn infont of the block not the script. Therefore I have used a click detector to open the gui. but this part is not working, any help?
The “CHPCVnon” is the model I want to spawn.

model = script.Parent.Parent.CHPCVnon	
modelbackup = model:Clone()
r = false

function onclicked()
    if (r == true) then return end
    r = true
    modelbackup = modelbackup:Clone()
    model:remove()
    wait(1)
    modelbackup.Parent = script.Parent.Parent
    modelbackup:MakeJoints()
    model = modelbackup
    modelbackup = model:Clone()
    wait(5)
    r = false
end

script.Parent.ClickDetector.MouseClick:connect(onclicked)
1 Like

You do not use a ClickDetector for Guis.
If you would like to create a click event on a text button it would look something like this:

TextButton.MouseButton1Down:Connect(function()
if (r == true) then return end
    r = true
    modelbackup = modelbackup:Clone()
    model:remove()
    wait(1)
    modelbackup.Parent = script.Parent.Parent
    modelbackup:MakeJoints()
    model = modelbackup
    modelbackup = model:Clone()
    wait(5)
    r = false
end)
1 Like

Sorry if I didn’t write it right but I used a click detector for the brick to open the gui not for the text button.

1 Like

Which part of your code is referencing the GUI then, it is not being added at all.

2 Likes

Owo chp crown vic. In order to spawn a vehicle you must respect FE so the clickdetector should have fired a event that spawned a car in a server script.

1 Like

ClickDetectors register on the server aswell, I use them alot.

@clash_ofsss, this is a server script, right? I don’t see anything about a GUI in your script.

2 Likes

omg thank you Fps, yeah I got it to work with some youtube.

1 Like