At Station Trigger

--When player is at the Station (no damage over time)
local ATSTATION_TRIGGER = script:GetCustomProperty("AtStationTrigger"):WaitForObject()

-- nil OnBeginOverlap(Trigger, Object)
-- A player is in the cart; they entered the trigger
function InsideStationDetect(trigger, other)
    if other:IsA("Player") then
        other:SetResource(_G._resource2,1) -- gives this player a variable (_atStation) and sets it to 1
        print("Player entered the station.")
    end
    if other.name == "MidPoint" then -- detect Cart entering the station
        _G.Cart["_rotations"] = _G.Cart["_rotations"] + 1 -- the cart enters the station so up the _rotations count
        print (other.name," - The cart has entered the station! ",_G.Cart["_rotations"]," rotation(s).")
    end   
    
end
function OutsideStationDetect(trigger, other)
    if other:IsA("Player") then
        other:SetResource(_G._resource2,0) -- gives this player a variable (_atStation) and sets it to 0
        print("Player left the station.")
    end
    if other.name == "MidPoint" then -- detect Cart leaving the station
        print (other.name," - The cart has left the station!")
    end 
end
-- Connect trigger overlap event
ATSTATION_TRIGGER.beginOverlapEvent:Connect(InsideStationDetect)
ATSTATION_TRIGGER.endOverlapEvent:Connect(OutsideStationDetect)

Latest Posts