Hello, back again with another scripting problem.
I’m a beginner at scripting, keep that in mind lol.
This is a script to spawn these objects that fly through the air(dont worry about the air part) but I tested it out and as I expected, it didn’t work. No errors have shown up, it just doesn’t spawn the parts.
I don’t even know if I was supposed to use run service honestly but someone said its better than other loops.
local tumble = Instance.new("MeshPart")
local force = Instance.new("BodyForce")
local RunService = game:GetService("RunService")
RunService.RenderStepped:Connect(function()
wait(math.random(5, 6)) --thats set to really low wait time so I could test it---
tumble.Position = Vector3.new(math.random(2342, -2342), 159.941, -3017.581)
tumble.MeshId = "rbxassetid://7545230286"
tumble.Parent = workspace
tumble.TextureID = "rbxassetid://6879551990"
tumble.Material = Enum.Material.ForceField
tumble.Size = Vector3.new(20.218, 19.503, 16.909)
force.Parent = tumble
force.Force = Vector3.new(0,1,10000)
wait(math.random(10, 15))
tumble.Transparency = 0.8
force.Force = Vector3.new(0,0,0)
tumble:Destroy()
end)
Workspace in an event folder. Its a local script for all those wondering, should it not be a local script I’m guessing? Again. I’m awful at coding but I’m getting better so remember.
Yeah I don’t understand module scripts so I stayed away from that, I guess I’ll switch to a non local script but is there a loop I could use? I use while true do sometimes but I don’t know if thats ideal.
Okay so, you did spawn the part, you just destroyed it and tried to set the position on the destroyed part
also, you don’t need that wait when using rendered stepped if you’re trying to spawn it every frame
Put that local tumble inside the runservice function
your script should look like this
yeah, don’t use renderedstepped on a sever because it isn’t rendering frames, renderedstepped is only for clients, and should be used for visual effects only
If you want to update a part’s physical settings before physics and calculated (i.e fly-scripts and their bodyvelocitys) then use stepped, if you want to update a parts physical settings after physics are calculated then use heartbeat
Theres a lot of replies so I’ll just make this main comment.
I’m making loose objects roll over the ground in one direction, after a certain amount of time they get destroyed so it doesnt cause build up.
Also, it gets destroyed after waiting a bit, thats what I need.
I would like to spawn multiple but I don’t know how.
Questions:
How do I clone an original from rep-storage? I tried but I couldnt get it to work…
Do I need to use a normal script instead of local? It just needs to spawn objects that roll and then destroy, nothing specific for local players.
If I do switch it, do I use the “while true do” code to loop it?
I’m trying to make parts spawn at 10-20 seconds, and then they disappear after 15-20 seconds. Also it says the math.random function inside of the position setting is invalid because “intervals empty” do you know why that is?
local WeedMaker = {}
local OriginalWeed = PathToOriginalWeed
-- Anchor it!
function WeedMaker.NewWeed(StartingPosition,Force)
local NewWeed = OriginalWeed:Clone()
NewWeed.Anchored = false
NewWeed.Parent = workspace
NewWeed.Position = StartingPosition
local Force = Instance.new("BodyForce")
Force.Parent = NewWeed
Force.Force = Vector3.new(0,1,1000) -- I think this might not work, I don't know for sure, I dont really use bodyforces at all.
wait(10)
NewWeed:Destroy()
end
return WeedMaker
-- call WeedMaker.NewWeed()
yeah, you either set the max too high or set the minimum higher than the max
when using math.random() it uses the first number as the minum and the second as the maximum
if you set the minimum higher than the maximum, then you get an error like that
by the way, you can get decimals anymore from math.random()
You have to set that stuff yourself.
ya know what, i’ll make a good example of what to do ok? give me a second