local replicatedStorage = game.ReplicatedStorage
local roundtime = 120
local button = game.ReplicatedStorage:FindFirstChild("button")
local function rng()
local rngValue = math.random(17,17) --placeholder so the button spawns 100% of the time
if rngValue == 17 then
if button then
local buttonClone = button:Clone()
buttonClone.Parent = game.Workspace
local randomposition = Vector3.new(math.random(-52,52), 3, math.random(-52,52))
buttonClone:PivotTo(CFrame.new(randomposition))
task.wait(0.1)
local main = button.main
local press = main.ClickDetector
if press then
press.MouseClick:Connect(function()
local part = Instance.new("part",workspace)
part.Position = Vector3.new(math.random(-52,52), 3, math.random(-52,52))
part.Anchored = false
end)
end
end
end
end
for i = 1, roundtime do
rng()
task.wait(1)
end
#why wont the part spawn after clicking the button?
1 messages · Page 1 of 1 (latest)
** You are now Level 6! **
the buttons are spawning in as i want, but when i click on them the part wont spawn in
Can collide is on?
i think when u create a new part instance p has to be capitalized
that might be it @knotty cloak
no way its that simple
a small mistypo
yeah still doesnt work
hm
i felt so smart for catching that
but it wouldve been a problem anyway
does the part appear in workspace in the explorer
local press
nope
if press then
press.MouseClick:Connect(function()
local part = Instance.new("part",workspace)
part.Position = Vector3.new(math.random(-52,52), 3, math.random(-52,52))
part.Anchored = false```
shouldnt it be .mousebutton1click
this part doesnt work i think
its a clicketector
clickdetectors use mouseclick
cause when i put "print" it wont show up aswell
i thought he meant a gui button
i am very smart
no its for gui
i didnt realise you were on about a click detector
try this
`local replicatedStorage = game.ReplicatedStorage
local roundTime = 120
local button = replicatedStorage:FindFirstChild("button")
local function rng()
local rngValue = math.random(17, 17) -- Always spawns for now
if rngValue == 17 and button then
local buttonClone = button:Clone()
buttonClone.Parent = workspace
local randomPosition = Vector3.new(math.random(-52, 52), 3, math.random(-52, 52))
buttonClone:PivotTo(CFrame.new(randomPosition))
task.wait(0.1)
local main = buttonClone:FindFirstChild("main")
if main then
local press = main:FindFirstChild("ClickDetector")
if press then
press.MouseClick:Connect(function()
local part = Instance.new("Part")
part.Position = Vector3.new(math.random(-52, 52), 3, math.random(-52, 52))
part.Anchored = false
part.Parent = workspace
end)
end
end
end
end
for i = 1, roundTime do
rng()
task.wait(1)
end`
no way that changes anything
he added an if statement
holy shit it works
local press =
local main
local main = button.main
this accessed the original button
not the cloned one
oooh
U used pivotto for a vector3
so main doesnt refer to the one in workspce
Pivot is only for cframe
nuh uh
Replace it with moveto()
it still works
Really? Wait now idk
button is a model
Let me check
i think moveto() doesnt work on models
you can pivot with both properties of cframes
Send ss of output
;-;
** You are now Level 6! **
Moveto is server sided dawg
oh alr, thanks for the info
also while im still here
i need the part to have 50% of spawning
any ideas:>
local rng2 = math.random(1,2)
if rng2 == 2 then
local main = buttonClone:FindFirstChild("main")
if main then
local press = main:FindFirstChild("ClickDetector")
if press then
press.MouseClick:Connect(function()
local part = Instance.new("Part")
part.Position = Vector3.new(math.random(-52, 52), 3, math.random(-52, 52))
part.Anchored = false
part.Parent = workspace
end)
end
end
end```
this is what i tried to do
oh that seems way easier
yes yes feel free to tell all your friends how smart i am twin
yo the parts keep spawning
there isnt a 50%
or either im really fucking lucky
oh i actually dont think 0 is a valid input sorry
** You are now Level 9! **
do math.random(1,2) == 1 i think
so uhhh
if i put "math.random(1,2) == 1" it wont spawn any parts
but if its "math.random(1,2) == 2" then it will always spawn
show me
make sure ur generating a new number every time
you might only be generating one number
@knotty cloak
oh sorry
give me asec
if math.random(1, 2) == 2 then
print("2")
local main = buttonClone:FindFirstChild("main")
if main then
local press = main:FindFirstChild("ClickDetector")
if press then
press.MouseClick:Connect(function()
local part = Instance.new("Part")
part.Position = Vector3.new(math.random(-52, 52), 3, math.random(-52, 52))
part.Anchored = false
part.Parent = workspace
end)
end
end
elseif math.random == 1 then
print("1")
end```
i added print to see what it picks
it keeps picking 2
no
this is how it is in studio
no just make it else
instead of elseif
because rn its picking 2 different random numbers
every time you call math.random its a different random number
changing it to else broke the entire script
even without the "else if" part it keeps picking 2
it went up to 10
okay it works now with 1
but its still 100% no matter if its == 1 or ==2
js to make sure make it a variable in the line before
local random = math.random(1,2)
if random == 1 ...```
okay so i noticed something
it picks 1 or 2 normally its 50% chance
but its 50% it will spawn blocks every time or 50% it wont even spawn a single one
change it to this
local randomChance = math.random(1, 2)
if randomChance == 2 then
💀
send me a screenshot of the whole script js to make sure theres not a mistake elsewhere
local replicatedStorage = game.ReplicatedStorage
local roundTime = 120
local button = replicatedStorage:FindFirstChild("button")
local function rng()
local rngValue = math.random(17, 17) -- Always spawns for now
if rngValue == 17 and button then
local buttonClone = button:Clone()
buttonClone.Parent = workspace
local randomPosition = Vector3.new(math.random(-52, 52), 3, math.random(-52, 52))
buttonClone:PivotTo(CFrame.new(randomPosition))
task.wait(0.1)
local random = math.random(1,2)
if random == 2 then
print("2")
local main = buttonClone:FindFirstChild("main")
if main then
local press = main:FindFirstChild("ClickDetector")
if press then
press.MouseClick:Connect(function()
local part = Instance.new("Part")
part.Position = Vector3.new(math.random(-52, 52), 3, math.random(-52, 52))
part.Anchored = false
part.Parent = workspace
end)
end
end
end
end
end
for i = 1, roundTime do
rng()
task.wait(1)
end```
and if you put else on the same like as the if random == 2 then it doesnt print anything?
alr nvm i know why it wont work
it goes math.random once and then it decides for the rest of the script
i think i would have to use a loop for it
crashed my studio by accident 👍
okay im back
why you ask so much questions?
whats the problem
its supposed to spawn 1 part
like 50% chance it spawns in 1 part
not 100% of spawning hundredes of them 😭
local replicatedStorage = game.ReplicatedStorage
local roundTime = 120
local button = replicatedStorage:FindFirstChild("button")
local function rng()
local rngValue = math.random(17, 17)
if rngValue == 17 and button then
local buttonClone = button:Clone()
buttonClone.Parent = workspace
local randomPosition = Vector3.new(math.random(-52, 52), 3, math.random(-52, 52))
buttonClone:PivotTo(CFrame.new(randomPosition))
task.wait(0.1)
local randomChance = math.random(1, 2)
if randomChance == 2 then
print("2")
local main = buttonClone:FindFirstChild("main")
if main then
local press = main:FindFirstChild("ClickDetector")
if press then
press.MouseClick:Connect(function()
local part = Instance.new("Part")
part.Position = Vector3.new(math.random(-52, 52), 3, math.random(-52, 52))
part.Anchored = false
part.Parent = workspace
end)
end
end
elseif randomChance == 1 then
print("1")
end
end
end
for i = 1, roundTime do
rng()
task.wait(1)
end```
try this
so it fixed the hundreds problem
but it didnt fix the 100% problem
lmao 3 devs vs 1 script
its a place holder
its gonna be 1, 20 but i dont want to wait for it to spawn\
the math.random(17, 17) is about spawning the button
its gonna be 5% to spawn in the button and then 50% for the button to spawn a part
that clears alot
okay
u dont have random chance variabled
nvm
wait
im blind just
yo we need more scripters on this 😭
** You are now Level 7! **
think i fixed it
imma test it
okay i fixed it
local replicatedStorage = game.ReplicatedStorage
local roundTime = 120
local button = replicatedStorage:FindFirstChild("button")
local function rng()
local rngValue = math.random(17, 17) -- Always spawns for now
if rngValue == 17 and button then
local buttonClone = button:Clone()
buttonClone.Parent = workspace
local randomPosition = Vector3.new(math.random(-52, 52), 3, math.random(-52, 52))
buttonClone:PivotTo(CFrame.new(randomPosition))
task.wait(0.1)
local main = buttonClone:FindFirstChild("main")
if main then
local press = main:FindFirstChild("ClickDetector")
if press then
press.MouseClick:Connect(function()
local chance = math.random(1, 2)
if chance == 2 then
local part = Instance.new("Part")
part.Position = Vector3.new(math.random(-52, 52), 3, math.random(-52, 52))
part.Anchored = false
part.Parent = workspace
else
end
end)
end
end
end
end
for i = 1, roundTime do
rng()
task.wait(1)
end
try this
spawns the button with 100% and then 50% to spawn a part if u press the button
what doesnt spawn
nice
not much, but moved the local chance = math.random inside the press.MouseClick:Connect(function()
u had the logic in wrong place yea
thank you dude 🙏
np
took kinda time to figure it out, been only learning scripting for like 3 days now
easiest part of the project done
only couple days for me aswell
dude i got voting system and round system ahead of me