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

Respawning Trigger Event Not Working, How to fix?

Asked by 3 years ago

This is my first time questioning... Error: It Doesn't work at all --Expectation-- When I respawn or spawn in the game, A random number will generate from 1 to 2 if it's 1 then I get AK if it's 2 then I get a pistol when I die and get respawn I get another Random Number, and so on, so on --Expectation End--

local function AK47()
end)

function Secondary()
end

local Players = game:GetService("Players")
local RZ = game.ReplicatedStorage.Randomizer

local function onCharacterAdded(RZ)
    local RandomNumber = math.random(1, 2)
    print(RandomNumber)
    RZ.Value = RandomNumber
    if RZ.Value == 1 then
        AK47()
    end

    if RZ.Value == 2 then
        Secondary()
    end
end

local function onCharacterRemoving(RZ)
    RZ.Value = 0
end

local function onPlayerAdded(player)
    player.CharacterAdded:Connect(onCharacterAdded)
    player.CharacterRemoving:Connect(onCharacterRemoving)
end

Players.PlayerAdded:Connect(onPlayerAdded)
0
What part doesn't work? Are there errors? What do functions AK47 and Secondary do? radiant_Light203 1166 — 3y
0
Also, CharacterAdded returns the player's character. You cannot substitute a number value. Instead, consider initialising RZ as a local variable. radiant_Light203 1166 — 3y

Answer this question