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)

2 comments

0

What part doesn't work? Are there errors? What do functions AK47 and Secondary do?

0

Also, CharacterAdded returns the player's character. You cannot substitute a number value. Instead, consider initialising RZ as a local variable.