Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 4 years ago
1    script.Parent.MouseClick:Connect(function(player)
2        if player:FindFirstChild("leaderstats") and player.leaderstats:FindFirstChild("Money") then
3player.leaderstats.Money.Value = player.leaderstats.Money.Value + 1
4 
5script.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

0
whats the problem AnasBahauddin1978 715 — 4y

4 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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

1script.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 = Vector3.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
8end)

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.

0
thanks ill try it HauntedUSA_NEW 5 — 4y
0
also dont change values via client. use remote events for that CaioAlpaca 342 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

Instance:Clone()

math.Random(m,n)

These should help you :)

Log in to vote
0
Answered by
TGazza 1336 Moderation Voter
4 years ago

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:

01local Self = script.Parent.Parent
02local DistanceToCloneTo = 60
03script.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 = Vector3.new(XPos,YPos,ZPos)
12 
13    end
14end)
Log in to vote
0
Answered by 4 years ago

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.

Answer this question