Can someone help please

Hello there,

What I’m trying to do is when the player goes over the speed limit with there car they will get a Ticket. What I have done here it’s not working and idk why but I’ve tried so many ways and nothing is working.

Server Script

local Gui = script:WaitForChild("Ticket")
local speedLimit = script.Parent.Parent.Parent.SpeedLimit
local debounce = false

script.Parent.Touched:Connect(function(player)
	if debounce == false then
		debounce = true
		if player.ClassName == "DriveSeat" then
			print(math.floor(player.Velocity.magnitude))
			if player.Velocity.magnitude >= speedLimit.Value then
				local clone = Gui:Clone()
				clone.Parent = player.PlayerGui
				player.leaderstats.Pounds.Value = player.leaderstats.Pounds.Value - 100
				player.leaderstats.Bounty.Value = player.leaderstats.Bounty.Value + 7
				else
			end
		end
	end
end)


If someone can point out in my script that would be great!

                                               ⚠️ Warning ⚠️

I’m only trying to help

This code was made by AI

There are a few issues with your script that could be causing it to not work as intended.

First, you have a local variable called “debounce” that is set to false at the beginning of the script. However, you are not resetting the value of “debounce” to false at any point in the script, so it will always remain true after the first time the script is run. This means that the script will only run once, and then it will never run again because “debounce” will always be true.

Second, you are using the “Touched” event to detect when the player’s car touches the script. However, this event is triggered when any object touches the script, not just the player’s car. This means that the script could potentially be triggered by other objects in the game, which may not be what you want.

To fix these issues, you could try the following changes to your script.

  1. Reset the value of “debounce” to false after the script has run once. You could do this by adding a line of code at the end of the script that sets “debounce” to false, like this:
debounce = false
  1. Use a different event to detect when the player’s car touches the script. Instead of using the “Touched” event, you could use the “Collision” event, which is triggered when two objects collide with each other. You would need to add a “Part” object to the script, and then use the “Collision” event on that object to detect when the player’s car touches the script.

Here is an example of how you could rewrite your script using the “Collision” event.

local Gui = script:WaitForChild("Ticket")
local speedLimit = script.Parent.Parent.Parent.SpeedLimit

local part = script:WaitForChild("Part")

part.Collision:Connect(function(otherPart)
if otherPart.Parent:IsA("DriveSeat") then
local player = otherPart.Parent.Parent
print(math.floor(player.Velocity.magnitude))
if player.Velocity.magnitude >= speedLimit.Value then
local clone = Gui:Clone()
clone.Parent = player.PlayerGui
player.leaderstats.Pounds.Value = player.leaderstats.Pounds.Value - 100
player.leaderstats.Bounty.Value = player.leaderstats.Bounty.Value + 7
end
end
end)

I hope this helps! Let me know if you have any questions.

1 Like

Hey I tried what you suggested and nothing worked.

1 Like

Official_SimuIation = Hey I tried what you suggested and nothing worked.

what was the error

There was no error In the output

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.