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
            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

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.

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.

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:

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)
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