My game works perfectly in Studio, but it breaks in game?

Hello! My game is basically finished, I’ve made game passes, products, several maps and game modes, all that is left are a few touch-ups here and there. However, the main game script, which I have heavily tested, works perfectly in Studio, but when I play it in-game it just stops at the ‘(insert player name) blew up!’ No error in the console. I have recorded some proof to show you.

(Sorry in advance for lag!)

In Studio:

In-game:

Here is the part of the game script I notice it stops at, if that helps:

    assets.ParentChanged.Event:Connect(function(parent)
		potatoHolder = parent
		ReplicatedStorage.Status.Value = potatoHolder.Name .. " has the potato!"
	end)
	
	assets.Exploded.Event:Connect(function(player)
		if player then
			ReplicatedStorage.Status.Value = player.Name .. " blew up!"
		end
	end)
	
	while #getPlaying:Invoke() > 1 do
		local randomPlayer = getPlaying:Invoke()[math.random(1, #getPlaying:Invoke())]

		local potatoHolder = randomPlayer
		
		ReplicatedStorage.Status.Value = potatoHolder.Name .. " has the potato!"
		
		local potato = assets.Potato:Clone()
		potato.Parent = randomPlayer.Character

		while potato.Parent do task.wait() end
		task.wait(1)
	end

	table.insert(module.Winners, getPlaying:Invoke()[1])
	ReplicatedStorage.Status.Value = getPlaying:Invoke()[1].Name .. " didn't blow up!"

	module.RunTime = tick() - gameStartTime

	task.wait(1)

Any help is greatly appreciated!

Edit:
Okay so turns out my problems originate from this line, but every time I remove it or try to replace it with something else, it clones the potato every second.

while potato.Parent do task.wait() end
1 Like

Okay so turns out my problems originate from this line, but every time I remove it or try to replace it with something else, it clones the potato every second.

while potato.Parent do task.wait() end

My guess is that you didn’t stop the while #getPlaying:Invoke() > 1 do function after it’s blew up so it’s a infinite loop

try this

 assets.ParentChanged.Event:Connect(function(parent)
		potatoHolder = parent
		ReplicatedStorage.Status.Value = potatoHolder.Name .. " has the potato!"
	end)
	
	assets.Exploded.Event:Connect(function(player)
		if player then
			ReplicatedStorage.Status.Value = player.Name .. " blew up!"
		end
	end)
	
	while #getPlaying:Invoke() > 1 do
		local randomPlayer = getPlaying:Invoke()[math.random(1, #getPlaying:Invoke())]

		local potatoHolder = randomPlayer
		
		ReplicatedStorage.Status.Value = potatoHolder.Name .. " has the potato!"
		
		local potato = assets.Potato:Clone()
		potato.Parent = randomPlayer.Character

		while potato.Parent do task.wait() end
		task.wait(1)
        break
	end

	table.insert(module.Winners, getPlaying:Invoke()[1])
	ReplicatedStorage.Status.Value = getPlaying:Invoke()[1].Name .. " didn't blow up!"

	module.RunTime = tick() - gameStartTime

	task.wait(1)

Thank you, I will try that now!

Nothing happened, although it makes sense because while loops break automatically according to Roblox, not sure what’s causing it.

okay from what I understand, the game continues until there is 1 player left?
and the problem is the script stops at while potato.Parent do task.wait() end ?
sorry i’m confused lol

Yeah, that’s the problem and that is where the script stops.

okay so i think this gonna work now
so basically it wait until the exploded event is fired instead of potato.Parent

assets.ParentChanged.Event:Connect(function(parent)
    potatoHolder = parent
    ReplicatedStorage.Status.Value = potatoHolder.Name .. " has the potato!"
end)

assets.Exploded.Event:Connect(function(player)
    if player then
        ReplicatedStorage.Status.Value = player.Name .. " blew up!"
    end
end)


while #getPlaying:Invoke() > 1 do
    local randomPlayer = getPlaying:Invoke()[math.random(1, #getPlaying:Invoke())]

    local potatoHolder = randomPlayer
    
    ReplicatedStorage.Status.Value = potatoHolder.Name .. " has the potato!"
    
    local potato = assets.Potato:Clone()
    potato.Parent = randomPlayer.Character

    assets.Exploded.Event:Wait()
    
    task.wait(1)
end

table.insert(module.Winners, getPlaying:Invoke()[1])
ReplicatedStorage.Status.Value = getPlaying:Invoke()[1].Name .. " didn't blow up!"

module.RunTime = tick() - gameStartTime

task.wait(1)

Thank you so much, it worked amazingly!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.