I’m trying to make a spawn car script, where if a player pressed the button it has to decide between 2 options, Spawn a basic car Or spawn an advanced car. But I get an error stating that It attempted to index nil with function :FindFirstChildOfClass()
local localplayer = game.Players.LocalPlayer
local b = script.Parent.spawncar
local seat = true
b.MouseButton1Click:Connect(function()
a = localplayer.PlayerGui.CarGui:WaitForChild("firstSeat")
b = localplayer.PlayerGui.CarGui:WaitForChild("secondSeat")
if seat then
a.Visible = true
b.Visible = true
else
a.Visible = false
b.Visible = false
end
end)
a:FindFirstChildOfClass("TextButton").MouseButton1Click:Connect(function()
game.ReplicatedStorage.something:FireServer(false)
end)
b:FindFirstChildOfClass("TextButton").MouseButton1Click:Connect(function()
game.ReplicatedStorage.something:FireServer(true)
end)
local replicated = game:GetService("ReplicatedStorage")
local something = replicated:WaitForChild("Something")
local players = game:GetService("Players")
local player = players.LocalPlayer
local playergui = player:WaitForChild("PlayerGui")
local cargui = playergui:WaitForChild("CarGui")
local first = cargui:WaitForChild("firstSeat")
local second = cargui:WaitForChild("secondSeat")
local firstButton = first:WaitForChild("TextButton")
local secondButton = second:WaitForChild("TextButton")
local parent = script.Parent
local spawncar = parent:WaitForChild("spawncar")
local seat = true
spawncar.MouseButton1Click:Connect(function()
if seat then
seat = false
first.Visible = true
second.Visible = true
else
seat = true
first.Visible = false
second.Visible = false
end
end)
firstButton.MouseButton1Click:Connect(function()
something:FireServer(false)
end)
secondButton.MouseButton1Click:Connect(function()
something:FireServer(true)
end)