Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Script not identifying Value change?

Asked by 4 years ago

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

0
I've realised the problem the "elseif" should be an "if" on line 14 Bradolink 17 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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

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. Bradolink 17 — 4y
0
oh :|. sorry User#29913 36 — 4y
0
I figured out the problem, the "elseif" on line 14, should be an an if. But I appreciate the help :) Bradolink 17 — 4y
0
thanks :) User#29913 36 — 4y
Ad

Answer this question