I’m making a car delete UI , but the actual TextButton doesn’t delete the car when clicked.
I’ve tried using Instance.Activated as well as .MouseButton1Click, but neither work.
local Players = game:GetService("Players")
local DeleteCarUI = Players:WaitForChild("PlayerGui").DeleteCarUI
local DeleteButton = DeleteCarUI.Frame.TextButton
local function onActivated()
script.Parent.Parent.Parent.Parent:Destroy()
end
DeleteButton.MouseButton1Click:Connect(onActivated)
This is the same issue I ran into with my client. I have no idea how their spawners work, so I’m not sure how to retrieve the person whop spawned it, so I’m just doing the current player in the seat.
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local DeleteCarUI = LocalPlayer:WaitForChild("PlayerGui").DeleteCarUI
local DeleteButton = DeleteCarUI.Frame.TextButton
local function onActivated()
script.Parent.Parent.Parent.Parent:Destroy()
end
DeleteButton.MouseButton1Click:Connect(onActivated)
If your trying to delete a car using a GUI, you’ll have to use a RemoteEvent. Here’s something I made.
LocalScript (Place in GUI)
local Player = game.Players.LocalPlayer
local DeleteCarUI = script.Parent
local DeleteButton = DeleteCarUI.Frame.TextButton
DeleteButton.MouseButton1Click:Connect(function()
game.ReplicatedStorage.RemoteEvent:FireServer()
end)
Server Script
local event = game.ReplicatedStorage.RemoteEvent
event.OnServerEvent:Connect(function(player)
local findseat = player.Character.Humanoid.SeatPart
if findseat then
player.PlayerGui.DeleteCarUI.Enabled = false
findseat.Parent.Parent.Parent:Destroy()
end
end)
You may have to change some of the instances to delete the car, since it’s using the Seat from earlier to troubleshoot your previous issue. But this should look right from your explorer.
local Player = game.Players.LocalPlayer
local DeleteCarUI = Player:WaitForChild("PlayerGui")
local DeleteButton = DeleteCarUI.Frame.TextButton
DeleteButton.MouseButton1Click:Connect(function()
game.ReplicatedStorage.DeleteJeepEvent:FireServer()
end)
10:21:17.014 Workspace.PolLand.Body.ARV#5751914.VehicleSeat.DeleteUIActivate:3: attempt to index nil with 'WaitForChild' - Server - DeleteUIActivate:3
Like I said, that needs to be in a local script under the GUI. Once you do that just replace the DeleteCarUI variable with script.Parent.
Replace the ServerScript with this, it could also work without the script needing to be in the vehicle.
local event = game.ReplicatedStorage.RemoteEvent
event.OnServerEvent:Connect(function(player)
local findseat = player.Character.Humanoid.SeatPart
if findseat then
player.PlayerGui.DeleteCarUI.Enabled = false
findseat.Parent.Parent.Parent:Destroy()
end
end)