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

Why do my objects spawn not where I want them, and other times do?

I asked this question yesterday, but no one really replied except for kingdom who told me to put the ball in ReplicatedStorage instead of Lighting. I did this, but there was still no difference. It does the same thing. Sometimes the ball moves to the vector, and other times it doesn't. Also, no errors are in output. It'd be great if someone could explain why. All help is appreciated! Here's the script:

local part = script.Parent
local db = true
local model = game.ReplicatedStorage.Model:GetChildren()

function gum(hit)
	if hit then
		
			
			
			
			if hit.leaderstats.Money.Value >= 5 then
				db = false
				
				hit.leaderstats.Money.Value = hit.leaderstats.Money.Value - 5
				
			
			
			game.Workspace.tune:Play()
			wait(2)
			local ball = model[math.random(1,#model)]
			ball:Clone().Parent = game.Workspace
			ball.Position = Vector3.new(31,12,-6)
			ball.Anchored = false
			
			
			
			else
				print("You need more money!")
				
				
			end
			wait(1)
			db = true
		end
	end


part.ClickDetector.MouseClick:connect(gum)

Video to what is happening: https://www.youtube.com/watch?v=3ed029Lbt2E&feature=youtu.be

1 answer

✓ Accepted answer

It may be because your cloning the ball and putting it in workspace, yet your setting the position of the original. I would set the clone as a variable, local ball2=ball:Clone() and then doing the neccesary modifications to it, as in ball2.Parent=game.Workspace

2 comments

0

I think the reason that it sometimes work is that by the time that the ball is cloned, the script has already moved onto and executed the next line. Other times it may not be as fast, and it doesn't work.

0

Wow! I worked! Also, maybe you know why my debounce doesn't work? Even when I click once, I can still keep clicking, just like in the video. It'd be great if you could answer that.

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