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

Two Random Certain Positions?

Asked by 3 years ago

So basically I need some help with my Object Carry System. It can be found in the tool box and there is a video of it. There were a few mistakes the creator had made by accident and you need to create an action animation to go with it but I've figured it out all by myself. There are no more mistakes but I want to add to it so I've been experimenting to try and create a random position teleporter in my script so it will make the give teleport to two random location and pick one at random. Here's the ones I've fixed:

Anim Script:

while(1)do
    wait(1)
    while script.Parent.Anim.Value == 'true' do
        wait(10)
        workspace:FindFirstChild(script.Parent.Owner.Value).RightHand.JobBox:Destroy()
        script.Parent.Anim.Value = 'false'
        script.Parent.Taken.Value = 'false'
    end
end

Box Script

script.Parent.ClickDetector.MouseClick:Connect(function(player)
 local take = script.Parent.Parent.Taken
if take.Value == 'false' and script.Parent.Parent.Anim.Value == 'false' then
    take.Value = 'true'
    local box = script.Parent.JobBox:Clone()
    box.Anchored = false
    box.Parent = workspace:FindFirstChild(player.Name).RightHand

    local weld = Instance.new('Weld')
    weld.Parent = box
    weld.Part0 = box
    weld.Part1 = workspace:FindFirstChild(player.Name).RightHand
    weld.C0 = CFrame.new(1.5,0,0)
    script.Parent.Parent.Anim.Value = 'true'
    local char = workspace:FindFirstChild(player.Name)
    local flip = Instance.new("Animation")

        flip.AnimationId = "http://www.roblox.com/asset/?id=5681405205"
            flip.Parent = char
            local animloader2 = char.Humanoid:LoadAnimation(flip )
            animloader2:Play()
            script.Parent.Parent.Owner.Value = player.Name

while(1) do
    wait(1)
    if script.Parent.Parent.Anim.Value == 'false' then
    animloader2:Stop()

    end
end     

end
end)

Once you've done that there's one more bit of code and this is the part I need help with:

local position1 = (-66.91, 5.56, -100.99)
local position2 = (-66.91, 5.56, -100.99)

script.Parent.Touched:Connect(function(Hit)
    local player = game.Players:GetPlayerFromCharacter(Hit.Parent.Parent)
        print(Hit.Parent.Name)
        local char = Hit.Parent
    if Hit.Name == 'JobBox' then
        print('BOXHIT')
        script.Parent.Parent.Anim.Value = 'false'
        script.Parent.Parent.Taken.Value = 'false'
        player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 2
        Hit:Destroy()
        script.Parent.Parent.AnimScript.Disabled = true
        script.Parent.Parent.AnimScript.Disabled = false
        script.Parent.Position = math.random(position1, position2)--<== Here
    end
end)

Thank you.

0
Oh FailyPal 0 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

math.random cannot be used on vector3's. What you could do is make another variable and check it's value, and set the position to it. Here is an example:

local placeHolder
local Vec1 = Vector3.new(0,0,1)
local Vec2 = Vector3.new(1,0,0)

placeHolder = math.random(1,2) -- this will get 1 or 2

if placeHolder == 1 then

    object.Position = Vec1

else -- if it is 2 (if you have more than two values, you will have to use an elseif)

    object.Position = Vec2

end

So here is how we will implement that into your script:

local position1 = (-66.91, 5.56, -100.99)
local position2 = (-66.91, 5.56, -100.99)
local randomValue

script.Parent.Touched:Connect(function(Hit)

    randomValue = math.random(1,2)
    local player = game.Players:GetPlayerFromCharacter(Hit.Parent.Parent)
        print(Hit.Parent.Name)
        local char = Hit.Parent
    if Hit.Name == 'JobBox' then
        print('BOXHIT')
        script.Parent.Parent.Anim.Value = 'false'
        script.Parent.Parent.Taken.Value = 'false'
        player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 2
        Hit:Destroy()
        script.Parent.Parent.AnimScript.Disabled = true
        script.Parent.Parent.AnimScript.Disabled = false

    if randomValue == 1 then

          script.Parent.Position = position1

    else

          script.Parent.Position = position2

    end
    end
end)

Hope this fixed your problem!

0
That was really useful, thanks so much and this is my first time using this website, I will definitely use it again. Elimonater10000 33 — 3y
0
Yup, this website is definitely the website to ask for questions when you're starting out to script. User#32819 0 — 3y
Ad

Answer this question