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

NumberValue Update Inside the Script(?)

Asked by 2 years ago
local Part = script.Parent --whatever
local Front = Part.Position + Part.CFrame.LookVector
local Back = Part.Position - Part.CFrame.LookVector
TrackSpeed = script.Parent.Values.Speed

function OnTouch(hit)
    if (hit.Position - Front).magnitude < (hit.Position - Back).magnitude and hit.Name == 'TrainTrigger' then
        if hit.Chassis.Value == "Basic" then
            hit.Parent.Parent.Parent.Values.Speed.Value = TrackSpeed.Value
            print(string.format("Speed requested to be changed to %s", TrackSpeed.Value))
        elseif hit.Chassis.Value == "Advanced" then
            hit.Parent.Parent.Values.Speed.Value = TrackSpeed.Value
            print(string.format("Speed requested to be changed to %s", TrackSpeed.Value))
        end
    end
end
script.Parent.Touched:connect(OnTouch)

Is there a way to get this to look at the value of the NumberValue everytime the function is ran?

I'm trying to get this sensor working to where when a train runs over the sensor, the speed limit shown in a GUI in the cab gets changed to whatever Speed is set at

0
is this normal or local script? googlpeopel15 55 — 2y

Answer this question