In my previous question, I asked how I would make a randomized tree position every time a player chops it down. Fortunately, it was answered.
But the only thing is, that the after one randomized position, the tree always respawns in the same location. I have no idea why this happens, but it may be because of the code that was provided to me.
My current script:
local random = math.random(-100,100) script.Parent.Changed:Connect(function() if script.Parent.Value <= 0 then script.Parent.Parent.CanCollide = false script.Parent.Parent.Transparency = 1 script.Parent.Parent.Name = "cooling" wait(10) script.Parent.Parent.Name = "tree" script.Parent.Parent.Transparency = 0 script.Parent.Value = 3 script.Parent.Parent.CanCollide = true script.Parent.Parent.Position = Vector3.new(random,script.Parent.Parent.Position.Y,random); end end)
The script randomizes the first position of the tree, then it always respawns at the first randomized position.
Any help please?
Could this be because the random variable is defined at the beginning of the script so each time it runs it is the same. If you don’t want it to be the same move the location the variable is defined.
I apologize if I’m reading your script wrong but this might be the problem.
Happy Holidays! :)
Setting the random as a variable will make it the same all the time. If you want to something like a random variable you need to make a function but it would just be easier to do Vector3.new(math.random,math.random,math.random)