Car Spawner Script Not Working

Hello! When trying to interact with a proximity prompt to spawn a car, it doesn’t work. The script is a localscript placed under the car spawner object. For some reason, it won’t even make a print statement making me think it’s something to do with the wrong proximity prompt but it isn’t.

Thanks!

script.Parent.Interactor.Triggered:Connect(function(player)
    player.PlayerGui.Civ_Car_Spawn.Enabled = true
	print("test")
end)
4 Likes

Hey !
Take 5 minutes to read this, this should help you !

2 Likes

Didn’t really help as it’s keep mentioning using Proximity Prompt service for when a prompt is triggered, but there are way to many prompts to do that and it’s a little confusing. I already done this in the past with previous games and they worked great, don’t understand why its not working.

1 Like

Switch it to a normal script. (char)

2 Likes

Works but causes another issue.

It only enables the UI for the first time. If you open the UI and then close it and then try to open it again using the proximity prompt, it doesn’t work.

Do you get any errors in the output?

Also, maybe try doing player:WaitForChild("PlayerGui").

1 Like

does it print the “test”? like twice
if it does then it must be a misscoded close gui in the car ui

1 Like

it doesn’t even print when you try to open it for a second time.

Edit: Somehow now it is

The script to close the UI is

script.Parent.MouseButton1Up:Connect(function(player)
	game.Players.LocalPlayer.PlayerGui.Civ_Car_Spawn.Enabled = false
end)

well you see why do you have the player then in there?

For the local gui script it should be

local player = game.Players.LocalPlayer -- as it's a local script you can access the player.

script.Parent.MouseButton1Up:Connect(function()
     player.PlayerGui.Civ_Car_Spawn.Enabled = false
end)

As for the opener script did that work? from my advice?

then enable it when you open up the gui?

Yeah. So when you open the UI, it enables it.
When you close it, it disables it.

yeah i cant help on much stuff from now

So is it fixed or or it is not?

No, i’m explaining what it’s supposed to do.

You can open it and close it for the first time but you can’t open it a second.

A few problems:

  • LocalScripts don’t run in the Workspace. They only run in places like StarterPlayerScripts (technically PlayerScripts, where the local scripts get copied to) and PlayerGui
  • (If you want code to run locally from the workspace, create a Script and set it’s RunContext to Client)
  • Spawning a car shouldn’t be done from the client, you should do that on the server. If you change a script to be enabled from the client, it won’t replicate.

Basically, move your code to a Script and it should work fine. ProximityPrompt.Triggered works on the client and the server.

Also, unless you intentionally made the car spawner script to work with Enabled, it’s very likely this won’t work properly.

(To work with enabled the script would need to spawn a car then disable itself.)

Let me explain a little, so I have changed the car spawner to be a script and not a local script.

Another thing is that the car’s aren’t being spawned from the client. That’s a whole separate thing in the menu that’s handled by a local script that fires an event on the car to spawn and then a server script that spawns that car. I’ll try a couple different methods for disabling the UI.

I recommend having a car model hidden somewhere on the map, then clone it and teleport it to where you want it to “spawn”.

That’s actually a good idea, although I can see it getting messy if you have over 40 cars.

1 Like

Still hasn’t been fixed! Issue is still remaining the same.

use chatgpt
if anyone couldnt fix it
what about the script that when you spawn your car
send it fully here
the client script (when u fire) and the server script