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

Is there a better way of finding out whether the player is still seated?

Asked by 10 years ago

The following script goes into a seat.

local debounce = false

function onTouched(part)
    local player = part.Parent
    if debounce == false then
        debounce = true
        print("Debounce is On")
        end
    wait()
        gui = Instance.new("ScreenGui")
        local textbox = Instance.new("TextBox")
        local plr = Workspace.Parent.Players:FindFirstChild(player.Name)
        gui.Parent = plr.PlayerGui
        gui.Name = "TrainGui"
        textbox.Name = "TrainGui"
        textbox.Parent = gui
        textbox.Text = "Testing"
        textbox.BackgroundTransparency = 1
        textbox.Position = UDim2.new(0.5, 0, 0.2, 0)        
        wait(0.5)   
    if not script.Parent:FindFirstChild("SeatWeld")then
    print("Seat Weld has been lost")    
    gui:Remove()
    print("Gui Removed?")
    end 
debounce = false
end

script.Parent.Touched:connect(onTouched)

Sometimes 'Gui Removed?' gets printed but the gui that says testing is not removed and on other times it doesn't appear at all.

Is there a better way of finding out whether the player is still seated or is there something wrong in the script itself? ._.

Sorry if there's a rookie mistake somewhere here

0
:remove() is deprecated. Use :destroy() intead. gskw 1046 — 10y

2 answers

Log in to vote
0
Answered by 10 years ago
local Seat = script.Parent
local Player = nil
Seat.ChildAdded:connect(function(Child) --This event fires when a child is added to the seat
    if Child.Name == "SeatWeld" then --If the child's name is "SeatWeld"...
        Player = game.Players:GetPlayerFromCharacter(Child.Part1.Parent) --Get's the player from the SeatWeld
        if Player then --If the person seated is a legitimate player...
            --Code here
        end
    end
end)
Seat.ChildRemoved:connect(function(Child) --This event fires when a child is removed from the seat
    if Child.Name == "SeatWeld" then --If the child was the SeatWeld...
        if Player then --If the player still exists...
            --Code here
        end
    end
end)
Ad
Log in to vote
-2
Answered by
KAAK82 16
10 years ago

u ever hear of StoppedToucing()? Here or TouchEnded()? Here

0
Idiots! -_- He Said, Touch! Not Weld-Detecting! KAAK82 16 — 10y

Answer this question