1 | script.Parent.MouseClick:Connect( function (player) |
2 | if player:FindFirstChild( "leaderstats" ) and player.leaderstats:FindFirstChild( "Money" ) then |
3 | player.leaderstats.Money.Value = player.leaderstats.Money.Value + 1 |
4 |
5 | script.Parent.MaxActivationDistance = 0 |
6 | end |
7 | end ) |
thats my code im trying to make it so once u click it destroys then clones in a random location
You can use the method :Clone(), :Destroy() and math.random for the position.
1 | script.Parent.MouseClick:Connect( function (player) |
2 | if player:FindFirstChild( "leaderstats" ) and player.leaderstats:FindFirstChild( "Money" ) then |
3 | player.leaderstats.Money.Value = player.leaderstats.Money.Value + 1 |
4 | script.Parent.Parent:Clone().Position = Vector 3. new(math.random( 0 , 100 ), 0 , math.random( 0 , 100 )) |
5 | script.Parent.Parent:Destroy() --// Make sure you do this AFTER you clone the click detector. |
6 | script.Parent.MaxActivationDistance = 0 |
7 | end |
8 | 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.
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:
01 | local Self = script.Parent.Parent |
02 | local DistanceToCloneTo = 60 |
03 | script.Parent.MouseClick:Connect( function (player) |
04 | if player:FindFirstChild( "leaderstats" ) and player.leaderstats:FindFirstChild( "Money" ) then |
05 | player.leaderstats.Money.Value = player.leaderstats.Money.Value + 1 |
06 |
07 | local XPos = (math.random()*DistanceToCloneTo)-(math.random()*DistanceToCloneTo) |
08 | local ZPos = (math.random()*DistanceToCloneTo)-(math.random()*DistanceToCloneTo) |
09 | local YPos = 0 |
10 |
11 | Self.Position = Vector 3. new(XPos,YPos,ZPos) |
12 |
13 | end |
14 | 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.