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

Making this give a random weapon on touch?

Asked by
22To 70
9 years ago

Ok so basically when they touch it will give thema random weapon out of serverstorage but it wont work.

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(math.random())
            if Weapon then
                local newWeapon = Weapon:Clone()
                newWeapon.Parent = PlayerIsFound.Backpack
            else
                Debounce = false
                return

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


1 answer

Log in to vote
0
Answered by
Validark 1580 Snack Break Moderation Voter
9 years ago

Your problem is here:

game.ServerStorage(math.random())

This syntax is invalid. I believe you are trying to do something along the lines of this

(game.ServerStorage:GetChildren())[math.random(1,NumWeapons)]
--GetChildren creates a table of all Children inside ServerStorage, and then with the [] syntax we can access values of that table by their index.
Ad

Answer this question