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

I need help with making my brick with a clickdetector clone and spawn in some random location?

			script.Parent.MouseClick:Connect(function(player)
				if player:FindFirstChild("leaderstats") and player.leaderstats:FindFirstChild("Money") then
		player.leaderstats.Money.Value = player.leaderstats.Money.Value + 1

		script.Parent.MaxActivationDistance = 0
				end
			end)

thats my code im trying to make it so once u click it destroys then clones in a random location

1 comment

0

whats the problem

4 answers

You can use the method :Clone(), :Destroy() and math.random for the position.

script.Parent.MouseClick:Connect(function(player)
	if player:FindFirstChild("leaderstats") and player.leaderstats:FindFirstChild("Money") then
		player.leaderstats.Money.Value = player.leaderstats.Money.Value + 1
		script.Parent.Parent:Clone().Position = Vector3.new(math.random(0, 100), 0, math.random(0, 100))
		script.Parent.Parent:Destroy() --// Make sure you do this AFTER you clone the click detector.
		script.Parent.MaxActivationDistance = 0
	end	
end)

I'm pretty sure the names of those things give out what they do and how you use them.

You also don't need to set the MaxActivationDistance to 0 if you're destroying the old one.

2 comments

0

thanks ill try it

0

also dont change values via client. use remote events for that

Just a thought.

You don't need to actually clone an object to move it to a new position. The following code does similar to what you ask but it just moves the original to the new position as if you've destroyed it.

Code:

local Self = script.Parent.Parent
local DistanceToCloneTo = 60
script.Parent.MouseClick:Connect(function(player)
	if player:FindFirstChild("leaderstats") and player.leaderstats:FindFirstChild("Money") then
		player.leaderstats.Money.Value = player.leaderstats.Money.Value + 1

		local XPos = (math.random()*DistanceToCloneTo)-(math.random()*DistanceToCloneTo)
		local ZPos = (math.random()*DistanceToCloneTo)-(math.random()*DistanceToCloneTo)
		local YPos = 0

		Self.Position = Vector3.new(XPos,YPos,ZPos)

	end
end)

I think you need to add at the end something to connect clickdetected with RightMouseClick or something, I'm not sure, but you can try.

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