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

Is there something i can use that will give me more than 2 random arguments?

Asked by 4 years ago

Hi. First off, I'm just messing around with the code of someone else's work to help get a better understanding of how it works so I can make my own version without stealing all there code. I would like to make it so that the blood particles that spawn, spawn randomly on different limbs. It normally just spawns on the torso which looks weird.

I tried to use math.random to make a random value, but I want more than 2 arguments, is there some function that can do that? I'm not aware of it and I'm pretty new to coding.

0
I am somewhat confused as to what you mean.. Do you want to get multiple values from math.random? If so, I'd do a for loop to get multiple math.random values. Kyokamii 133 — 4y
0
they want to chose a random part of the body and put blood particles on that part Arkrei 389 — 4y

1 answer

Log in to vote
1
Answered by
Azarth 3141 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

I think I understand what you mean, you want to get a number of parts randomly to insert the fx? This can go in StarterCharacterScripts as a LocalScript. Next time include some code, normally people won't help otherwise.

local player = game.Players.LocalPlayer
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")

local limbs_to_affect = 3

math.randomseed(tick())
-- you need to randomize the randomizer

local function random_limbs()
    local parts = {}
    -- table to store limbs
    for i,v in pairs(character:GetChildren()) do 
        local part = v:IsA("BasePart")
        -- Is part a part?
        if part then 
            -- If so insert into parts table
            table.insert(parts, v)
            -- (table, index or 1 on default, value)
        end
    end
    repeat table.remove (parts, math.random(#parts) ) wait() until #parts == limbs_to_affect
    -- will error if there aren't enough limbs, write an upgrade
    return parts
end

humanoid.Died:Connect(function()
    for i,v in pairs( random_limbs() ) do
        -- loop through our limbs table
        Instance.new('Fire', v ) 
        -- parent fx to part
    end
end)
Ad

Answer this question