Roblox studio crashes

I tried to do a script, and when i runned it roblox just crashed, is this problem of my pc or script?
what does this script do, it generates position for coins, and adding them to workspace

for i = 1, 20 do

position = CFrame.new(math.random(-249,-146), 1,math.random(517,645)) + Vector3.new(math.random(47,587),0,math.random(32,999)) / 1000
local cl = nil

if math.random(1,2) == 1 then
		cl = game.ReplicatedStorage.Assets["Area 1"].BoxOfCoinsModel:Clone()
else
		cl = game.ReplicatedStorage.Assets["Area 1"].CoinsModel:Clone()
end

cl:SetPrimaryPartCFrame(position)
cl.Parent = workspace

end

The script instantly runs a for loop without yielding. Try adding wait() or task.wait()

for i = 1, 20 do

position = CFrame.new(math.random(-249,-146), 1,math.random(517,645)) + Vector3.new(math.random(47,587),0,math.random(32,999)) / 1000
local cl = nil

if math.random(1,2) == 1 then
		cl = game.ReplicatedStorage.Assets["Area 1"].BoxOfCoinsModel:Clone()
else
		cl = game.ReplicatedStorage.Assets["Area 1"].CoinsModel:Clone()
end

cl:SetPrimaryPartCFrame(position)
cl.Parent = workspace
wait() --add to yield the script
end
1 Like

i tried it, it didnt help, i even tried one second

This is not nearly enough repetition to cause roblox to crash. Is that the entire code?

uhh, yeah? maybe its a error with my pc

Are you sure that this is the script crashing roblox? Try disabling it and see if it still crashes.

it doesnt crash without code, i tried it so many times

phew it was other script in part that i accidently writed, it was cloning it self and clone was cloning it self too so it was crashing, yeah a little bit dumb
sorry lol

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.