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

[SOLVED] Why do my guns only work for one player on the server?

Hey there! So my problem is that the guns I am replicating from ReplicatedStorage only work for one player.

Here is that replication script:

game:GetService("Players").PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		wait(1)
		character:WaitForChild("Humanoid").Died:Connect(function()
			player:WaitForChild("Backpack"):ClearAllChildren()
			for i, v in pairs(character:GetChildren()) do
				if v:IsA("Tool") then
					v:Destroy()
				end
			end

			player.CharacterAdded:Wait()
		end)
	end)
end)

game.ReplicatedStorage:WaitForChild("RemoteEvents"):WaitForChild("AddToolsEvent").OnServerEvent:Connect(function(player)
	local spawnPoints = workspace.Spawns:GetChildren()
	local character = player.Character or player.CharacterAdded:Wait()
	character.HumanoidRootPart.Anchored = false
	
	local ranSpawn = math.random(1, #spawnPoints)
	local chosen = spawnPoints[ranSpawn]
	
	character:FindFirstChild("HumanoidRootPart").CFrame = chosen.CFrame + Vector3.new(0,8,0)
	
	local primary = player.Primary
	local secondary = player.Secondary
	local melee = player.Melee
	local equipment = player.Equipment
	
	for i, v in pairs(game.ReplicatedStorage:WaitForChild("Primary"):GetChildren()) do
		if v.Name == primary.Value then
			local clone = v:Clone()
			clone.Parent = player:WaitForChild("Backpack")
		end
	end	
	
	for i, v in pairs(game.ReplicatedStorage:WaitForChild("Secondary"):GetChildren()) do
		if v.Name == secondary.Value then
			local clone = v:Clone()
			clone.Parent = player:WaitForChild("Backpack")
		end
	end	
	
	for i, v in pairs(game.ReplicatedStorage:WaitForChild("Melee"):GetChildren()) do
		if v.Name == melee.Value then
			local clone = v:Clone()
			clone.Parent = player:WaitForChild("Backpack")
		end
	end	
	
	for i, v in pairs(game.ReplicatedStorage:WaitForChild("Equipment"):GetChildren()) do
		if v.Name == equipment.Value then
			local clone = v:Clone()
			clone.Parent = player:WaitForChild("Backpack")
		end
	end	
end)

Any help is greatly appreciated!

4 comments

0

by "only work for one player" you mean that only one player receives them or everyone receives them and they work only for one player out of all?.

0

All players receive them, but only one player can use the guns.

0

this must be problem with the guns themselfs, try making print statements in gun code and see where the script stops.

0

Alright, I'll try it and see what I get

1 answer

So the problem was that some stupid little anti cheat code I made was causing problems. I edited the code and now everything is working as intended.

2 comments

0

nob

0

:(

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