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?
#Action Button Not Always Working/Buggy
1 messages · Page 1 of 1 (latest)
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
if you want the gui to constantly reset on spawning then turn on the resetOnSpawn property in the screenGui
yeah ur killing me
What is this
** You are now Level 1! **
The issue is that it stays with the player when they die, I want it to go away
oOOoOoh
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
you could detect whenever the humanoid dies and then turn off their gui but the resetOnSpawn property should already do that for you
if that for some reason doesn't work you can always do this ig:
humanoid.Died:Connect(function()
gui.Enabled = false
end()
late update, ik, but here is what i mean.
ima try the humanoid.died rn
np
I can finally release my game now ur the goat