Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Making this give random weapon out Server storage?

It keeps getting error..it needs to be when they touch it, it will give them a random weapon out of server storage

RespawnTime = 1200
Debounce = false

script.Parent.Touched:connect(function (Hit)
    local HumanoidIsFound = Hit.Parent:FindFirstChild("Humanoid")
    local PlayerIsFound = game.Players:GetPlayerFromCharacter(Hit.Parent)
    if Hit.Parent and HumanoidIsFound and HumanoidIsFound.Health > 0 and PlayerIsFound then
        if not Debounce then
            Debounce = true
            local Weapon = (game.ServerStorage:GetChildren())[math.random(1,NumWeapons)]
            if Weapon then
                local newWeapon = Weapon:Clone()
                newWeapon.Parent = PlayerIsFound.Backpack
            else
                Debounce = false
                return

            end
            wait(RespawnTime)
            Debounce = false
        end
    end
end)


4 comments

0

What's the error? .-. Don't just say "there's an error" and not give it. It's probably because "NumWeapons" doesn't exist and that it should be "#NumWeapons" if it did exist.

0

how do i make it exist?

0

Create a variable for it.

0

Add it into the script. Make a table called NumWeapons, which is equal to 'ServerStorage:GetChildren()'

1 answer

✓ Accepted answer

You did not define NumWeapns, you can either define this as #game.ServerStorage:GetChildren() or rather than putting NumWeapons you can specify #game.ServerStorage:GetChildren().

This discussion is preserved as it was. New answers, comments, and votes are closed.