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

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

Asked by 2 years ago
Edited 2 years ago

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!

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?. imKirda 4491 — 2y
0
All players receive them, but only one player can use the guns. ColdFoxy07 76 — 2y
0
this must be problem with the guns themselfs, try making print statements in gun code and see where the script stops. imKirda 4491 — 2y
0
Alright, I'll try it and see what I get ColdFoxy07 76 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago

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.

0
nob imKirda 4491 — 2y
0
:( ColdFoxy07 76 — 2y
Ad

Answer this question