Tool clone depending on a BoolValue

Hey! I’ve been recently working on a riot script, and I have come to a little problem. Once the riot starts, player normally gets a weapon cloned into his inventory (backpack), without any problems. However, once he respawns, he doesn’t get it again, which he is meant to.

Part of the script:

local function giveWeapon()
	if game.ReplicatedStorage.IsRiotOngoing.Value == true then
		if player.Team == game.Teams.Civilian then
			script.AKM:Clone().Parent = player.Backpack
		end
	end
end
game.Players.PlayerAdded:Connect(function()
	player.CharacterAdded:Connect(function()
		wait(0.5)
		giveWeapon()
	end)
end)

use parameters on the giveWeapon() function and use them when you call it

local function giveWeapon(player)
	if game.ReplicatedStorage.IsRiotOngoing.Value == true then
		if player.Team == game.Teams.Civilian then
			script.AKM:Clone().Parent = player.Backpack
		end
	end
end
game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function()
		wait(0.5)
		giveWeapon(player)
	end)
end)

What do you mean exactly?

characteeeers

i updated the message with a script

Oh, okay. Well I tried player before, though it still didn’t work. Imma try your exact script and I’ll see.

Still doesn’t work. Btw, the script which I sent is a Local-Script.

it should not be a localscript

I can’t make it a server script, as there is a OnClientEvent() function. Do you think separating this script from the OnClientEvent() function and making it a server script would help?

yeah you should separate them into 2 different scripts then

1 Like

Yep, works perfectly now. Thank you!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.