Problem Spawn Script

Why is this code not working:

script.Parent.Parent.Parent.Parent.Information.Spawnbutton.MouseButton1Click:Connect(function()
	if plr:GetRankInGroup(script.Parent.GroepID.Value) > script.Parent.GroepRank.Value then 
	if not game.Workspace:FindFirstChild(plr.Name.."'s Car") then 
	local Copy = SSS:FindFirstChild(script.Parent.AutoSpawn.Value)
	local Clone = Copy:Clone()
	Clone.Name = plr.Name.."'s Car"
	Clone.Parent = workspace
		end
	else
		plr:Kick("Anti Exploit")
		end
end)

This script is for a Spawn Script for a car, the value have the good name value.

here my error:

Players.IndexSearchx.PlayerGui.EenhedenSpawn.MainFrame.ScrollingFrame.basic.Script:23: attempt to index nil with 'Clone
1 Like

SSS:FindFirstChild(script.Parent.AutoSpawn.Value) cannot be found. Try printing out script.Parent.AutoSpawn.Value and see if it exists in SSS. If you could attach a screenshot of the explorer too that would be helpful.

If SSS is ServerScriptStorage then make sure this isn’t a LocalScript since clients cannot see anything in ServerScriptStorage.

Yeah thats working now, can u help me with a other problem?

I have now a problem that its spawns but if i click on the other vehicle it spawns the same one. Here some pictures/scripts.

local Settings = require(script.Parent.Parent.Parent.Parent.Settings)
local Informatie = script.Parent.Parent.Parent.Parent.Information
local plr = script.Parent.Parent.Parent.Parent.Parent.Parent
local SSS = game:GetService("ServerStorage")
script.Parent.Parent.Parent.Parent.Information.Spawnbutton.MouseButton1Click:Connect(function()
		if plr:GetRankInGroup(script.Parent.GroepID.Value) > script.Parent.GroepRank.Value then 
			if not game.Workspace:FindFirstChild(plr.Name.."'s Car") then 
				local Clone = SSS:FindFirstChild(script.Parent.AutoSpawn.Value):Clone()
				Clone.Name = plr.Name.."'s Car"
				Clone.Parent = workspace
				plr.PlayerGui.EenhedenSpawn:Destroy()
			else
				game.Workspace:FindFirstChild(plr.Name.."'s Car"):Destroy()
				local Copy = SSS:FindFirstChild(script.Parent.AutoSpawn.Value)
				local Clone = Copy:Clone()
				Clone.Name = plr.Name.."'s Car"
				Clone.Parent = workspace
				plr.PlayerGui.EenhedenSpawn:Destroy()
			end
		end
end)

image
image

As in it spawns the same car as the one you clicked on, or the one you originally had? By the looks of it you’re using whatever value the AutoSpawn is returning, how are updating that?

The button clones every time, see this script:

local plr = script.Parent.Parent.Parent
local Informatie = script.Parent.Information
script.Parent.MainFrame.ScrollingFrame.basic:Clone()
local Settings = require(script.Parent.Settings)
for i, v in pairs(Settings.Cars) do
	local Clone = script.Parent.MainFrame.ScrollingFrame.basic:Clone()
	Clone.Parent = script.Parent.MainFrame.ScrollingFrame
	Clone.Text = v.AutoNaam
	Clone.Visible = true
	Clone.Ranktext.Text = v.RankNaam
	Clone.GroepID.Value = v.GroepID
	Clone.GroepRank.Value = v.GroepRank
	Clone.AutoNaam.Value = v.AutoNaam
	Informatie.AutoNaam.Text = Clone.AutoNaam.Value
	Clone.AutoSpawn.Value = v.ServerStorageNaam
	script.Parent.MainFrame.ScrollingFrame.basic.Position = script.Parent.MainFrame.ScrollingFrame.basic.Position + UDim2.new(0,0,0.09,0)

end

Okay I’m understanding the cloning part and putting them into ScrollingFrame, how are you detecting the button clicks of the “basic” TextButton that you’re cloning?

I’m noticing once you hit Spawnbutton it’s just pulling from whatever script.Parent.AutoSpawn.Value is,

Can you try something slightly different? Under the “Information” Frame, make a StringValue called CarName and have the value to whatever you was as default, if they click any of the cloned frames for each car, make it change the CarName Value to that car, and then read that value when they press Spawnbutton?

Or lay it how you want, but maybe try it this way, I’m just slightly confused on how exactly you’re detecting the car that they pick.

P.S: You can change script.Parent.Parent.Parent.Parent.Information.Spawnbutton to Informatie.Spawnbutton