Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Script not identifying Value change?

Added a fuel and damage system to an AC6 Chassis. The Damage system calculates the damage correctly but fails to activate the 2nd part of the script which kills the vehicle.

https://gyazo.com/e72f3ea13cd6861b108c0fcbb3deba43

The strange part, when you jump out the vehicle and enter it, the script registers the damage.

https://gyazo.com/07c7ac4a7385759fca95028b10ae8ae9

The Script is a Local Script.

wait(.1)
local car = script.Parent.Car.Value
local dmghandler = car.Body.dmghandler
local per = script.Parent.AC6T_Stock_Gauges.dmg.Text
wait(.1)

function crashed(crash)
	wait(.1)
	if dmghandler.Velocity.Magnitude > crash.Velocity.Magnitude + 5 and crash.CanCollide == true or crash.Velocity.Magnitude > dmghandler.Velocity.Magnitude + 5 then
		script.Disabled = true
		dmghandler.dmg.Value = dmghandler.dmg.Value - dmghandler.Velocity.Magnitude / 0.4
		script.Disabled = false
		
	elseif 0 >= dmghandler.dmg.Value then
		print("Car Dead")
					script.Disabled = true
					dmghandler.dmg.Value = 0
					script.Parent.Values.Torque.Value = 0
					script.Parent.Values.Gear.Value = 0
					script.Parent.IsOn.Value = false
					script.Parent.Dead.Value = true
					
			end
		end
	
dmghandler.Touched:connect(crashed)

Any help is appreciated.

Thanks, Bradolink

1 comment

0

I've realised the problem the "elseif" should be an "if" on line 14

1 answer

✓ Accepted answer

You can detect whether or not the player has hit the car. Fix:

wait(.1)
local car = script.Parent.Car.Value
local dmghandler = car.Body.dmghandler
local per = script.Parent.AC6T_Stock_Gauges.dmg.Text
wait(.1)

function crashed(crash)
    wait(.1)
    if dmghandler.Velocity.Magnitude > crash.Velocity.Magnitude + 5 and crash.CanCollide == true or crash.Velocity.Magnitude > dmghandler.Velocity.Magnitude + 5 then
        script.Disabled = true
        dmghandler.dmg.Value = dmghandler.dmg.Value - dmghandler.Velocity.Magnitude / 0.4
        script.Disabled = false

    elseif 0 >= dmghandler.dmg.Value then
        print("Car Dead")
                    script.Disabled = true
                    dmghandler.dmg.Value = 0
                    script.Parent.Values.Torque.Value = 0
                    script.Parent.Values.Gear.Value = 0
                    script.Parent.IsOn.Value = false
                    script.Parent.Dead.Value = true

            end
	elseif crash.Parent = game.Players:GetPlayerFromCharacter(crash.Parent) then
		print("Player touched car, not taking damage")
	end
        end

dmghandler.Touched:connect(crashed)

-1bitPro

4 comments

0

I appreciate what you sent me as it is something I planned to do, but im looking at as if you're driving the car and you hit an object. Which is what I did, the player doesn't actually damage the car due to it not being a high enough velocity but this can work as a failsafe. Also your script does have errors in it but I can fix that.

0

oh :|. sorry

0

I figured out the problem, the "elseif" on line 14, should be an an if. But I appreciate the help :)

0

thanks :)

This discussion is preserved as it was. New answers, comments, and votes are closed.