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!
There are a few potential issues with your script.
Make sure that the “Ticket” GUI object exists in the server script’s parent (i.e. the part that the speed camera is attached to).
Make sure that the “SpeedLimit” object exists in the parent of the parent of the parent of the server script’s parent (i.e. the parent of the vehicle).
Check the spelling and case of all your object and variable names. For example, “script.Parent.Touched” should be “script.Parent.Touched” (capital T).
Make sure that you are using the correct syntax for the “Connect” function. It should be: “:Connect(function()” instead of “:Connect(function”.
Make sure that you are using the correct syntax for the “Clone” function. It should be: “:Clone()” instead of “:Clone”.
Make sure that you are using the correct syntax for accessing the player’s GUI. It should be: “player.PlayerGui” instead of “player.PlayerGui”.
Make sure that the “leaderstats” object exists in the player’s character model and that the “Pounds” and “Bounty” objects exist within it.
In your script, debounce is set to false at the start, but never changed back to false again, which means that as you run through it, the debounce == false won’t be triggered again.
Edit: It looks like you’ve already posted this??? Please don’t repost within short time frames. Can someone help please - #5 by Official_SimuIation
Anyways, first of all, what @ValtryekRBLX said is true.
Where is this script located? And is the player parameter really a player? Because, in your second if-statement, you’re checking if the player is a seat.
First of all, Player is a driveseat not a player. Second, if you want the player you should go and check for a seatdweld that connects to the character and then get the player from character.
It looks like you’re trying to check if the player’s car is going over the speed limit and give them a ticket if they are. Here are a few things you could try to fix the issue you’re experiencing:
As mentioned, you should use player.Parent.Parent to get the player object, since player is a DriveSeat object.
You should also add a debounce timer to prevent the script from executing multiple times. You can do this by using a wait() function after setting debounce to true . This will allow the script to execute only once until the debounce timer has finished.
Make sure that the speedLimit object is in the right place in the hierarchy. You can check this by printing the speedLimit object to the output and verifying that it is the object you expect it to be.
You should also make sure that the speedLimit value is being set correctly. If the value is not set or is set to a very low number, the player’s car may never be detected as going over the speed limit.
I hope this helps! Let me know if you have any questions or if you need further assistance.
local Players = game:GetService("Players")
local speedLimit = script.Parent.Parent.Parent:WaitForChild("SpeedLimit")
debounce = false
print(speedLimit.Value.."kph | Has Been Set for Andover Speed Camera")
script.Parent.Touched:Connect(function(hit)
if debounce == false then
debounce = true
local player = hit.AssemblyLinearVelocity.Magnitude
if hit.Parent:FindFirstChild("Humanoid") then
if (math.floor(hit.AssemblyLinearVelocity.Magnitude((((10/12) * 1.09728))))) >= speedLimit.Value then
local player = Players:FindFirstChild(hit.Parent.Name)
print("Players Speed before they get a ticket "..math.floor(hit.AssemblyLinearVelocity.Magnitude))
if hit.AssemblyLinearVelocity.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 + 15
wait(2)
clone:Destroy()
else
end
end
end
debounce = false
end
end)
I just edited it a bit. Sorry for wasting your time
Try using the GetPlayerFromCharacter function to check if a player is in the DriveSeat. 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:IsA(“DriveSeat”) then
local player = game.Players:GetPlayerFromCharacter(player.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
else
end
end
end
end)