#Action Button Not Always Working/Buggy

1 messages · Page 1 of 1 (latest)

versed tapir
#

Hi everyone! This is my last bug I need to fix before I release my game so that's fun. Basically my game is about smashing cars into other cars (amazing I know) and every car has an action button (image button in gui) that the player gets every time they sit in the car's seat. My script that handles this works most of the time, but not all of the time. Sometimes when players die with the button in their gui it does not come back and more. Any ideas?

#

local cooldown = 6
local canAction = true
local driver = nil

local function carAction() -- Action
--fill here
end

-- Gui
script.Parent.VehicleSeat.ChildAdded:Connect(function(child)
if child.Name == "SeatWeld" then
local human = child.part1.Parent:findFirstChild("Humanoid")
if (human ~= nil) then
driver = human
end
end
end)

script.Parent.VehicleSeat.ChildRemoved:connect(function(child2)
if (child2.Name == "SeatWeld") then
local human = child2.part1.Parent:findFirstChild("Humanoid")
if (human ~= nil) then
driver = nil
end
end
end)

while true do
wait(0.1)
if driver ~= nil and not game.Players:findFirstChild(driver.Parent.Name).PlayerGui.ScreenGui:FindFirstChild("ActionButton") and canAction == true then
canAction = false
local GUI = script.ActionButton:Clone()

    GUI.Parent = game.Players:findFirstChild(driver.Parent.Name).PlayerGui.ScreenGui

    GUI.MouseButton1Click:Connect(function()  -- Action
        if GUI then
            GUI:Destroy()
            carAction()
            
            wait(cooldown)
            canAction = true
        end
    end)

end

end

#

.

#

,

#

.

#

this is the main part I am focused on

#

.

#

,

#

script.Parent.VehicleSeat.ChildAdded:Connect(function(child)
if child.Name == "SeatWeld" then
local human = child.part1.Parent:findFirstChild("Humanoid")
if (human ~= nil) then
driver = human
end
end
end)

script.Parent.VehicleSeat.ChildRemoved:connect(function(child2)
if (child2.Name == "SeatWeld") then
local human = child2.part1.Parent:findFirstChild("Humanoid")
if (human ~= nil) then
driver = nil
end
end
end)

while true do
wait(0.1)
if driver ~= nil and not game.Players:findFirstChild(driver.Parent.Name).PlayerGui.ScreenGui:FindFirstChild("ActionButton") and canAction == true then
canAction = false
local GUI = script.ActionButton:Clone()

    GUI.Parent = game.Players:findFirstChild(driver.Parent.Name).PlayerGui.ScreenGui

    GUI.MouseButton1Click:Connect(function()  -- Action
        if GUI then
            GUI:Destroy()
            carAction()
            
            wait(cooldown)
            canAction = true
        end
    end)

end

end

solar lake
#

Youre

#

Uh

#

Is the script parented to the gui

#

Also use the format

modest saffron
burnt lantern
versed tapir
loud masonBOT
#

studio** You are now Level 1! **studio

versed tapir
#

Why the ‘’’’’’

#

I’ve scripted for like 2 years and I’ve never seen this ;-;

solar lake
#

Discord format

#
print("Hi")
versed tapir
versed tapir
#

Yeah I can do that

#
local canAction = true
local driver = nil

local function carAction() -- Action
    local CLETUS = game.ServerStorage.CarParts.Cletus:Clone()
    local car = script.Parent
    local primaryPart = car.PrimaryPart

    car.VehicleSeat.Action:Play()
    CLETUS.Parent = script.Parent
    CLETUS:SetPrimaryPartCFrame(CFrame.new(primaryPart.CFrame.X, primaryPart.CFrame.Y + 10, primaryPart.CFrame.Z))
end

-- Gui
script.Parent.VehicleSeat.ChildAdded:Connect(function(child)
    if child.Name == "SeatWeld" then
        local human = child.part1.Parent:findFirstChild("Humanoid") 
        if (human ~= nil) then
            driver = human
        end
    end
end)

script.Parent.VehicleSeat.ChildRemoved:connect(function(child2)
    if (child2.Name == "SeatWeld") then    
        local human = child2.part1.Parent:findFirstChild("Humanoid") 
        if (human ~= nil) then
            driver = nil
            if game.Players:FindFirstChild(human.Parent.Name).PlayerGui.ScreenGui:FindFirstChild("ActionButton") then
                game.Players:findFirstChild(human.Parent.Name).PlayerGui.ScreenGui.ActionButton:Destroy()
            end
            wait(cooldown)
            canAction = true
        end
    end
end)


while true do
    wait(0.1)
    if driver ~= nil and not game.Players:findFirstChild(driver.Parent.Name).PlayerGui.ScreenGui:FindFirstChild("ActionButton") and canAction == true then
        canAction = false
        local GUI = script.ActionButton:Clone()

        GUI.Parent = game.Players:findFirstChild(driver.Parent.Name).PlayerGui.ScreenGui

        GUI.MouseButton1Click:Connect(function()  -- Action
            if GUI then
                GUI:Destroy()
                carAction()

                wait(cooldown)
                canAction = true
            end
        end)
    end
end```
#

@modest saffron @solar lake @burnt lantern

#

here is also the hiearchy

modest saffron
#

if that for some reason doesn't work you can always do this ig:

humanoid.Died:Connect(function()
gui.Enabled = false
end()
versed tapir
versed tapir
#

ima try the humanoid.died rn

versed tapir
#

DUDE IT WORKS!!!

#

TYSM : D

modest saffron
versed tapir