hmmm, i think something is not updating values, try to add print next to RNG command line.
like
local ranx = math.random(minx, maxx)
print("test")
local ranz = math.random(minz, maxz)
hmmm, i think something is not updating values, try to add print next to RNG command line.
like
local ranx = math.random(minx, maxx)
print("test")
local ranz = math.random(minz, maxz)
Try setting the CFrame before Parenting?
local Template = script.Parent:FindFirstChildWhichIsA("Model")
local PP = Template.HumanoidRootPart
local x = PP.Position.X
local y = PP.Position.Y
local z = PP.Position.Z
local minx = x - 500
local maxx = x + 500
local minz = z - 750
local maxz = z + 750
local rolls = 0
local maxrolls = 100
local RunService = game:GetService("RunService")
local studiomaxrolls = 5
local ranx,ranz
if RunService:IsStudio() then
while true do
if rolls >= studiomaxrolls then
Template:Destroy()
script:Destroy()
break
end
rolls += 1
ranx = math.random(minx, maxx)
ranz = math.random(minz, maxz)
print(ranx)
print(ranz)
local Clone = Template:Clone()
Clone:SetPrimaryPartCFrame(CFrame.new(ranx, y, ranz))
Clone.Parent = script.Parent
end
end
I removed the isStudio
variable since you can check RunService:IsStudio()
directly
The other thing you could do is put the everything in a function and call that function from a while loop. Sometimes calling the function multiple times works.
For the X value I got -102 from “rerun” 2-5
Results in the same problem…
Hmmm … this is super weird. Maybe try using this code to get a random number?
math.random()*(maxx-minx) + minx
-- and
math.random()*(maxz-minz) + minz
The math.random function with no parameters returns a random between [0.0,1.0), so this is the equivalent of your random code but it will not always return an integer number.
I’m honestly pretty stumped. I guess you could try messing with your randomseed (using math.randomseed), but other than that I don’t have any other ideas.
math.random(nothing) returns numbers like
0.57624736597824635786586
(I found that out my naming all of my service tostring(math.random())
)
@arrowman888 @EmbatTheHybrid @aca1231231
UPDATE: I tried making it super random by randomizing the maxx, minx, minz, and maxz, and THEN making the random number using the newer values, however it still didn’t work, here’s the relevant snippet from the code:
if isStudio == true then
while true do
if rolls >= studiomaxrolls then
Template:Destroy()
script:Destroy()
end
rolls = rolls + 1
local minx2 = math.random(minx - 50, minx + 50)
local maxx2 = math.random(maxx - 50, maxx + 50)
local minz2 = math.random(minz - 50, minz + 50)
local maxz2 = math.random(maxz - 50, maxz + 50)
local ranx = math.random(minx2, maxx2)
local ranz = math.random(minz2, maxz2)
-- print (ranx .. "," .. y .. "," .. ranz)
local Clone = Template:Clone()
Clone:SetPrimaryPartCFrame(CFrame.new(ranx, y, ranz))
Clone.Parent = script.Parent
end
end
Yep! It returns numbers in the range [0.0,1.0) that aren’t integers. With some math, those numbers can be turned into non-integer numbers between the given range.
I ran this code in studio and it worked for me:
local Template = script.Parent:FindFirstChildWhichIsA("Model")
local PP = Template.HumanoidRootPart
local x = PP.Position.X
local y = PP.Position.Y
local z = PP.Position.Z
local minx = x - 500
local maxx = x + 500
local minz = z - 750
local maxz = z + 750
local rolls = 0
local maxrolls = 100
local isStudio = false
local RunService = game:GetService("RunService")
if RunService:IsStudio() then
isStudio = true
end
local studiomaxrolls = 5
if isStudio == true then
while true do
if rolls >= studiomaxrolls then
Template:Destroy()
script:Destroy()
break
end
rolls = rolls + 1
math.randomseed(rolls)
local ranx = math.random()*(maxx-minx) + minx
local ranz = math.random()*(maxz-minz) + minz
print (ranx)
print (ranz)
local Clone = Template:Clone()
Clone.Parent = script.Parent
Clone:SetPrimaryPartCFrame(CFrame.new(ranx, y, ranz))
end
end
Output:
10:23:33.064 430.65828231356 - Server - test:50
10:23:33.065 -648.23510747763 - Server - test:51
10:23:33.066 -240.17694369361 - Server - test:50
10:23:33.067 494.14353829081 - Server - test:51
10:23:33.068 -337.13953443904 - Server - test:50
10:23:33.069 683.58567313776 - Server - test:51
10:23:33.070 -482.2025176584 - Server - test:50
10:23:33.070 -99.756102696435 - Server - test:51
10:23:33.071 316.29626754092 - Server - test:50
10:23:33.071 -489.27393228615 - Server - test:51
Omg it worked thanks
@EmbatTheHybrid @PseudoPerson @aca1231231 @RFL890 @arrowman888
There’s still one more problem though, after the NPC is teleported, the HumanoidRootPart doesn’t move “in sync” with the rest of the body, causing the NPC to break.
More information on that on this devforum post (I just made)
what is :isStudio
???
It checks if your running the game in studio or in the roblox client
whats the differance???
See, I cut off a bit of the code to make it simpler to read. So basically what the full code does is it checks to see if I’m in studio or the client, and if I’m in the studio it basically duplicates the zombies 5x instead of 100x. This is the case because when you test things in studio, it turns your PC into the server, and my PC quite frankly isn’t as powerful as the big one at Roblox (their own servers)
whats the roblox client???
so the roblox client is basically ROBLOX
Ya client = actual game
studio = making the game