Hi, I need to make these parts randomly generated
for example make them stay close but randomly spawn just by changing their positions, how i do that?
Hi, I need to make these parts randomly generated
for example make them stay close but randomly spawn just by changing their positions, how i do that?
Correct me if Iām wrong on what youāre asking.
Clone a part and if you need it to be close, pick a random number and add it to a partās position.
Like this:
local orignialPart = --this is the part where all the parts will group together with
local clonedPart = Instance.new ("Part")
clonedPart.Parent = game.Workspace
clonedPart.Position = originalPart.Position + Vector3.new(math.random(0,10), 0, math.random(0,10)
If you need it to repeat - you can make it as many times as you want with this:
local orignalPart = -- again, this is what the parts will revolve around
for i = 1,2 do --the two is an example I used just change the number (2) to your liking
local part = originalPart:Clone()
part.Position = originalPart.Position + Vector3.new(math.random(0,10), 0, math.random(0,10)
end
Did that solve your problem?
I tried the script and the part was not cloned I donāt know what Iām doing wrong ā¦
code:
local Player = game:GetService("Players")
script.Parent.Touched:Connect(function(hit)
local PlayerCharacter = Player:GetPlayerFromCharacter(hit.Parent)
if PlayerCharacter then
local orignialPart = game.Workspace.Coins
local clonedPart = Instance.new ("Part")
clonedPart.Parent = game.Workspace
clonedPart.Position = orignialPart.Position + Vector3.new(math.random(0,10), 0, math.random(0,10))
local Leaderstats = PlayerCharacter:WaitForChild("leaderstats")
Leaderstats.Cash.Value = Leaderstats.Cash.Value + 10
script.Parent:Destroy()
end
end)
I need that part to be cloned near it and randomly generated
While I open Roblox studio, try replacing all of the āPositionā with āCFrameā.
Like this.
local Player = game:GetService("Players")
script.Parent.Touched:Connect(function(hit)
local PlayerCharacter = Player:GetPlayerFromCharacter(hit.Parent)
if PlayerCharacter then
local originalPart = game.Workspace.Coins
local clonedPart = originalPart:Clone()
clonedPart.Parent = game.Workspace
clonedPart.CFrame = originalPart.CFrame + Vector3.new(math.random(0,10), 0, math.random(0,10))
local Leaderstats = PlayerCharacter:WaitForChild("leaderstats")
Leaderstats.Cash.Value = Leaderstats.Cash.Value + 10
script.Parent:Destroy()
end
end)
I changed a few other things in case that was the problem.
didnāt cloned anywhere
oh at the moment of touching her she cloned, I need her to clone herself before having touched her, how would that be?
Any errors? Also maybe the part is spawning below the baseplate so it is just being destroyed. Try changing this line:
clonedPart.Position = orignialPart.Position + Vector3.new(math.random(0,10), 0, math.random(0,10))
Change it to this:
clonedPart.Position = orignialPart.Position + Vector3.new(math.random(0,10), 10, math.random(0,10))
I had some typos, I fixed it. Did that fix it?
Also, it doesnāt affect the Y-axis, I did that on purpose, so that shouldnāt be the problem.
I just saw it work and create the clone, but the clone does not give money like the other part
Oh if you want it to also give money then do this:
local Player = game:GetService("Players")
local db = false
script.Parent.Touched:Connect(function(hit)
if db == false then
db = true
local PlayerCharacter = Player:GetPlayerFromCharacter(hit.Parent)
if PlayerCharacter then
local orignialPart = game.Workspace.Coins
local clonedPart = script.Parent:Clone()
clonedPart.Position = orignialPart.Position + Vector3.new(math.random(0,10), 5, math.random(0,10))
clonedPart.Parent = game.Workspace
local Leaderstats = PlayerCharacter:WaitForChild("leaderstats")
Leaderstats.Cash.Value = Leaderstats.Cash.Value + 10
script.Parent:Destroy()
end
wait(0.5)
db = false
end
end)
I found the issue. You seem to have added a:
script.Parent:Destroy()
at the end, causing it the original part to die, so there would be only one clone.
local Player = game:GetService("Players")
local db = false
script.Parent.Touched:Connect(function(hit)
if db == false then
db = true
local PlayerCharacter = Player:GetPlayerFromCharacter(hit.Parent)
if PlayerCharacter then
local orignialPart = game.Workspace.Coins
local clonedPart = script.Parent:Clone()
clonedPart.Position = orignialPart.Position + Vector3.new(math.random(-10,10), 0, math.random(-10,10))
clonedPart.Parent = game.Workspace
local Leaderstats = PlayerCharacter:WaitForChild("leaderstats")
Leaderstats.Cash.Value = Leaderstats.Cash.Value + 10
end
wait(0.5)
db = false
end
end)
Unless you wanted it to be like that, then this should probably solve your problem.
Thank you guys so much! Really, thank you for all the support and the problem is solved
Thanks for giving me the solution, but I think that @NoodleCrystal10 deserves it. He wrote most of the code, I just changed a couple lines.