Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

My pet spawn in the same position, how do I make the position random?

Asked by 6 years ago
Edited 6 years ago

I made a script where when you click a button, a pet will come out and follow you, and I made it that more than one pet can follow, but the result I got is a disaster. Because when I click the button again the pet spawn in the same place as the other pet, and it all squeeze/stack together and look like a monster. How can I make it that each spawn and follow you in a different position?

Example:

https://cdn.discordapp.com/attachments/456967793397727233/485850971281555477/unknown.png

here is the script, it is a local script

local char = script.Parent.Parent
local hum = char:FindFirstChild("Humanoid")
local head = char:FindFirstChild("Head")
local pet = script.Parent

local maxFloat = 1
local floatInc = 0.025
local sw = false
local fl = 0

while true do
    wait()
    if not sw then
        fl = fl + floatInc
        if fl >= maxFloat then
            sw = true
        end
    else
        fl = fl - floatInc
        if fl <=-maxFloat then
            sw = false
        end
    end
    if pet ~= nil and hum ~= nil and head ~= nil then
        if hum.Health >= 0 then
            local cf = head.CFrame * CFrame.new(3,2+fl,3)
            pet.BodyPosition.Position = Vector3.new(cf.x,cf.y,cf.z)
            pet.BodyGyro.CFrame = head.CFrame * CFrame.new(3,0,-3)
        else
            break
        end
    end
end
0
I would say, make a invisible (and CanCollide = false) bricks that are welded to your body, then make an math.random function that spawns the animal on the random places. Oficcer_F 207 — 6y
0
how do you do that? RainbowBeastYT 85 — 6y

Answer this question