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

Why dosen't my ClientEvent work?

The script in the gun (Local)

game.ReplicatedStorage.EventsAndValues.GiveGun.OnClientEvent:Connect(function()
	
	local player = game.Players.LocalPlayer
	local gun = game.ReplicatedStorage.Handgun
	gun.Parent = player.Backpack
	
end)

The line of code that fires on a brick touch

game.ReplicatedStorage.EventsAndValues.GiveGun:FireAllClients()

1 answer

✓ Accepted answer

for one, you aren't cloning the handgun, you're just parenting it to the player's backpack, which means that every player can only get one handgun before it errors

also, you shouldn't even be giving the player the gun on the client

i can almost guarantee that gun has some amount of serverside code, and you won't be able to check if they have the gun on the server

-- replace the FireAllClients line with this
for _, player in pairs(game.Players:GetPlayers()) do
	local gun = game.ReplicatedStorage.Handgun:Clone()
	gun.Parent = player.Backpack
end

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