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

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

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
		
			
			db = false
			
			if hit.leaderstats.Money.Value >= 5 then
				
				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
			
			db = true
			
			else
				print("You need more money!")
				
				
			end
		end
	end


part.ClickDetector.MouseClick:connect(gum)

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

1 answer

Try moving the debounce reset outside of the conditional statement.

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

function gum(hit)
	if hit.leaderstats.Money.Value >= 5 and db then
		db = false
		hit.leaderstats.Money.Value = hit.leaderstats.Money.Value - 5
		game.Workspace.tune:Play()
		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


part.ClickDetector.MouseClick:Connect(gum)

You also never check for the debounce in any conditional.

Good Luck!

If I helped, please don't forget to accept my answer.

1 comment

0

Ok, I tried what you suggested but no difference. Here's a video to what's going on: https://www.youtube.com/watch?v=3ed029Lbt2E&feature=youtu.be

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