Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Boosts Spawn Script Isn't Spawning More Than One Boost?

Boost Spawn Script

local Rep = game:GetService("ReplicatedStorage")
local Boosts = Rep:WaitForChild("Boosts")

local BoostObj = {}
local BoostSpawn = {}

for i,v in pairs(workspace.BoostSpawns:GetChildren()) do
	table.insert(BoostSpawn,v)
end

for i,v in pairs(Boosts:GetChildren()) do
	table.insert(BoostObj,v)
end

local rand = BoostObj[math.random(1,#BoostObj)]
local Clone = rand:Clone()
Clone.Parent = workspace.Boosts
local RandSpawn = BoostSpawn[math.random(1,#BoostSpawn)]
repeat
	wait()
	RandSpawn = nil
	RandSpawn = BoostSpawn[math.random(1,#BoostSpawn)]
until RandSpawn.Spawned.Value == false
RandSpawn.Spawned.Value = true
Clone:SetPrimaryPartCFrame(RandSpawn.Position)
Clone.Spawn.Value = workspace.BoostSpawns[RandSpawn.Name]

while wait(5) do
	local rand = BoostObj[math.random(1,#BoostObj)]
	local Clone = rand:Clone()
	Clone.Parent = workspace.Boosts
	local RandSpawn = BoostSpawn[math.random(1,#BoostSpawn)]
	repeat
		wait()
		RandSpawn = nil
		RandSpawn = BoostSpawn[math.random(1,#BoostSpawn)]
	until RandSpawn.Spawned.Value == false
	RandSpawn.Spawned.Value = true
	Clone:SetPrimaryPartCFrame(RandSpawn.Position)
	Clone.Spawn.Value = workspace.BoostSpawns[RandSpawn.Name]
end

Boost's Boost script:

local Hitbox = script.Parent.Hitbox
local Amnt = script.Parent.Amount

function boost(player,Amnt)
	local Info = player.Info
	local Click = Info.ClickValue
	Click.Value = (Click.Value)*Amnt
	wait(15)
	Click.Value = (Click.Value)/Amnt
	local Spawn = script.Parent.Spawn.Value
	Spawn.Spawned.Value = false
	script.Parent:Destroy()
end

Hitbox.Touched:Connect(function(hit)
	if hit.Parent then
		if hit.Parent:FindFirstChild("Humanoid") then
			if game.Players:GetPlayerFromCharacter(hit.Parent) then
				local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
				for i,v in pairs(script.Parent:GetChildren()) do
					if v:IsA("BasePart") then
						v:Destroy()
					end
				end
				boost(Player,Amnt.Value)
			end
		elseif hit.Parent.Parent then
			if hit.Parent.Parent:FindFirstChild("Humanoid") then
				if game.Players:GetPlayerFromCharacter(hit.Parent.Parent) then
					local Player = game.Players:GetPlayerFromCharacter(hit.Parent.Parent)
					boost(Player,Amnt.Value)
					for i,v in pairs(script.Parent:GetChildren()) do
						if v:IsA("BasePart") then
							v:Destroy()
						end
					end
				end
			end
		end
	end
end)

Error: Workspace.Boosts.Boost.Script:11: attempt to index local 'Spawn' (a nil value)

It wont spawn the boost because of the script inside of the boost erroring

2 comments

0

Do not use Lighting as storage.

0

Ok I changed it to Replicated Storage but I still have the same error

1 answer

✓ Accepted answer

###Assuming Spawn is an ObjectValue, you're getting the error because the Value of the ObjectValue is set to nil, thus script.Parent.Spawn.Value referring to nil. A fix would be setting the Value of the ObjectValue to what you need it to be. You should instead consider directly accessing the Value, and the Spawn variable should hold the ObjectValue instead.

local Hitbox = script.Parent.Hitbox
local Amnt = script.Parent.Amount

local function boost(player,Amnt) -- use local if you're not going to use it global 
    local Info = player.Info
    local Click = Info.ClickValue
    Click.Value = Click.Value*Amnt
    wait(15)
    Click.Value = Click.Value/Amnt
    local Spawn = script.Parent.Spawn -- hold the ObjectValue

    if Spawn.Value then -- if the value is not nil
        Spawn.Value.Spawned.Value = false -- directly access the Value property 
        script.Parent:Destroy()
    else -- if no value
        return -- stop the function 
    end
end

###On a side note, do not use Lighting as storage, it is unsupported by Roblox and storage services ReplicatedStorage and ServerStorage exist for these very reasons. Good day.

5 comments

0

I set the spawn's value to the spawn object in the boost spawn script and i changed it to replicatedStorage

0

I will show you an example of what you should do

0

Ok i will try that

0

It still errors with the same thing

0

well thanks for your help ill try to fix it on my own

This discussion is preserved as it was. New answers, comments, and votes are closed.