Help on semi-working script

Please help me on this code, which first works then doesnt work again

SPS_Limit = 10
CitationAmount = 50
script.Parent.Transparency = 1
script.Parent.Touched:Connect(function(Part)
	if Part:IsA("VehicleSeat") and Part.Occupant then
		local Player = game.Players:GetPlayerFromCharacter(Part.Occupant.Parent)
		local GotSpeed = math.floor(Part.Velocity.Magnitude/2)
		if not Player.PlayerGui:FindFirstChild("Citation") and GotSpeed > SPS_Limit then
			Player.leaderstats.Money.Value = Player.leaderstats.Money.Value - CitationAmount
			local Citation = script.Citation:Clone()
			Citation.Frame.Description.Text = "Aşırı Hız. Speed Limit: " .. SPS_Limit .. ". Your Speed: " .. GotSpeed
			Citation.Parent = Player.PlayerGui
			Citation.Frame.LocalScript.Disabled = false
		end
	end
end)

Ekran Resmi 2021-05-24 18.24.35

Localscript

script.Parent:WaitForChild("Okay").MouseButton1Down:connect(function()
script.Parent.Click:Play()
script.Parent:TweenPosition(UDim2.new(0.3, 0,-1,0),'In','Back',.5,false)
wait(.5)

end)

So what is the problem exactly?

What part of the code doesn’t work the second time? Try print debugging the server-script to see whether it’s just the LocalScript.

No errors on the output but Ill try and reply

It just works once and no more sign of working

That is extremely vague, what “just works once” is it the Touched event? Are you trying to say the touched event fires once and then stops firing even though parts are touching it?

Yes. I pass the speed limit with my car and It does not fire touched event I guess

Okay I’m sensing you don’t understand what the Touched event does.

Is what you are calling a “speed limit” a BasePart?


Let me explain to you what the Touched event is.

Each BasePart in workspace has an event that will fire when any other BasePart touches it. That even is called “Touched”. It returns one argument, the part that “touched” (other part)

If you have a Part called on the ground and you have a Touched event connected to it. Then you drive over it, the event should fire.

I think you need to read the script to understand what I mean better

I found that after

if Part:IsA("VehicleSeat") and Part.Occupant then

it stucks there so there might be a problematic one after that

Okay so if it’s not passing the if statement, even though the Touched event fires nothing will happen.

1 Like

maybe try changing this line to Part.Occupant:IsA("Humanoid")

Nothing changed sadly :frowning:

Fixed by me. Removed this from the script

1 Like