The tools disappear when another player joins roblox studio

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want fix this issue
  2. What is the issue? Include screenshots / videos if possible!
    the tools disappear when another player joins roblox studio, here is video
    robloxapp-20241108-1125256.wmv (2.7 MB)

And also I made script in serverscriptservice

local weaponsFolder = game.ServerStorage:WaitForChild("Weapons")
local weapons = weaponsFolder:GetChildren()

local function giveWeapons(player)
	local backpack = player:WaitForChild("Backpack")
	if backpack then
		for _, weapon in ipairs(weapons) do
			local clone = weapon:Clone()
			clone.Parent = backpack
		end
	end
end

local function onCharacterAdded(character)
	local player = game.Players:GetPlayerFromCharacter(character)
	if player then
		task.wait(0.1) 
		giveWeapons(player)
	end
end

local function onPlayerAdded(player)
	player.CharacterAdded:Connect(onCharacterAdded)
	if player.Character then
		giveWeapons(player)
	end
end

game.Players.PlayerAdded:Connect(onPlayerAdded)

1 Like

starter pack exists you know

you dont have to write code for this

You should consider putting all of the weapons into StarterPack instead of making a script for it.

1 Like

Iā€™ve already done this, it still doesnā€™t help.

Iā€™ve already done this, it still doesnā€™t help

Make sure you add a check to make sure that other players donā€™t have a tool. You might have a bug with your cloning the way itā€™s scripted.

Could you help somehow please?

Maybe issue with weapons? Or what

Would you mind sending the code for each of your tools? Also, like @Exozorcus said, you donā€™t need code for this.

This should be pretty straight forwardā€¦ Trying out task.defer here also.
ServerScript in ServerScriptService:

local weaponsFolder = game.ServerStorage:WaitForChild("Weapons")

local function giveWeapons(player)
   local backpack = player:WaitForChild("Backpack")
   local weapons = weaponsFolder:GetChildren()
   for _, weapon in ipairs(weapons) do
   	weapon:Clone().Parent = backpack
   end
end

game.Players.PlayerAdded:Connect(function(player)
   player.CharacterAdded:Connect(function(character)
   	task.defer(function()
   		giveWeapons(player)
   	end)
   end)
end)

Really like how this worksā€¦

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
	
--         This part will run with every spawn

	end)
end)

When theyā€™re in starterpack, the issue is same

Doesnā€™t work, maybe issue with weapons

Here is script

local punch = script.Parent
local remote = punch.Remote
local hitpart = punch.HitPart
local humanoidlist = {}
local touch
local debris = game:GetService("Debris")
local Players = game:GetService("Players")
local cooldownTime = 3

function CheckHumanoid(hum)
	for _, v in pairs(humanoidlist) do
		if v == hum then
			return true
		end
	end
	return false
end

function Velocity(x, y, z, maxtorque, maxforce, vector, hit)
	local attachment = Instance.new("Attachment", hit)
	local linear = Instance.new("LinearVelocity", hit)
	linear.MaxForce = maxforce
	linear.Attachment0 = attachment
	linear.RelativeTo = Enum.ActuatorRelativeTo.World
	linear.VectorVelocity = vector

	local angular = Instance.new("AngularVelocity", hit)
	angular.MaxTorque = maxtorque
	angular.AngularVelocity = Vector3.new(x, y, z)
	angular.Attachment0 = attachment
	angular.RelativeTo = Enum.ActuatorRelativeTo.Attachment0

	debris:AddItem(angular, 0.5)
	debris:AddItem(linear, 0.5)
	debris:AddItem(attachment, 0.5)
end

local function initialize(char)
	print("Initializing punch for character:", char.Name)
	local hrp = char:FindFirstChild("HumanoidRootPart")

	local weld = hitpart:FindFirstChild("Weld")
	if weld then
		weld.Part0 = char:FindFirstChild("Right Arm")
		weld.Part1 = hitpart
	end

	punch.Enabled = true 
	local humanoid = char:FindFirstChildOfClass("Humanoid")
	if humanoid then
		humanoid.Died:Connect(function()
			punch.Enabled = false
			if touch then
				touch:Disconnect()
				touch = nil
			end
		end)
	end
end

function ApplyRagdoll(character)
	local humanoid = character:FindFirstChildOfClass("Humanoid")
	if humanoid then
		humanoid:ChangeState(Enum.HumanoidStateType.Physics)
	end

	for _, part in pairs(character:GetChildren()) do
		if part:IsA("BasePart") then
			part:SetNetworkOwner(nil)
			if part:FindFirstChildOfClass("Motor6D") then
				local constraint = Instance.new("BallSocketConstraint")
				constraint.Parent = part
				constraint.Attachment0 = Instance.new("Attachment", part)
				constraint.Attachment1 = Instance.new("Attachment", part.Parent:FindFirstChild(part.Name))
				debris:AddItem(constraint, 2)
			end
		end
	end

	task.wait(2)

	if humanoid then
		humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
	end

	for _, part in pairs(character:GetChildren()) do
		if part:IsA("BasePart") then
			part:SetNetworkOwner(Players:GetPlayerFromCharacter(character))
		end
	end
end

function startCooldown(player)
	player:SetAttribute("CooldownActive", true)
	punch.Enabled = false

	local interval = 0.1
	local steps = cooldownTime / interval
	for i = 1, steps do
		punch.Name = "[" .. string.format("%.1f", cooldownTime - (i * interval)) .. "]"
		task.wait(interval)
	end

	punch.Name = "Punch"
	punch.Enabled = true
	player:SetAttribute("CooldownActive", false)
end

remote.OnServerInvoke = function(plr, action)
	if action == "Swing" then
		if not plr:GetAttribute("CooldownActive") then
			punch.Enabled = false
			plr:SetAttribute("CooldownActive", true)

			delay(0.2, function()
				touch = hitpart.Touched:Connect(function(hit)
					if hit and hit.Parent then
						local hum = hit.Parent:FindFirstChildOfClass("Humanoid")
						if hum then
							local check = CheckHumanoid(hum)
							local otherhrp = hit.Parent:FindFirstChild("HumanoidRootPart")
							if otherhrp then
								local delta = otherhrp.Position - hitpart.Position
								if not check then
									table.insert(humanoidlist, hum)
									Velocity(0, 0, 25, 40, 9999999, delta * 10, otherhrp)
									hum:TakeDamage(20)
									hitpart.Hit:Play()
									ApplyRagdoll(hit.Parent)

									-- Add creator tag
									local creatorTag = Instance.new("ObjectValue")
									creatorTag.Name = "creator"
									creatorTag.Value = plr
									creatorTag.Parent = hum
									debris:AddItem(creatorTag, 2)  -- Adjust duration as needed

									task.wait(1)
									humanoidlist = {}
								end
							end
						end
					end
				end)
			end)

			delay(1, function()
				if touch then
					touch:Disconnect()
					touch = nil
				end
			end)

			startCooldown(plr)
			return true
		end
	end
end

punch.Equipped:Connect(function()
	local char = punch.Parent
	print("Punch equipped by:", char.Name)
	initialize(char)
end)

Players.PlayerAdded:Connect(function(player)
	-- Š”Š¾Š±Š°Š²Š»ŃŠµŠ¼ Š°Ń‚Ń€ŠøŠ±ŃƒŃ‚ Š“Š»Ń ŠŗуŠ»Š“Š°ŃƒŠ½Š°
	player:SetAttribute("CooldownActive", false)

	player.CharacterAdded:Connect(function(character)
		task.wait(1)
		if punch.Parent ~= character then
			print("Re-parenting punch to character's right arm.")
			punch.Parent = character:FindFirstChild("Right Arm")
		end

		initialize(character)
	end)
end)

punch.SwingSound.OnServerEvent:Connect(function(plr)
	hitpart.Swing:Play()
end)

Ya I reposted that. Ended up posting my start at testing and not the finished one.

I sent my script from 1 of weapons

Here is client script (local script)

local punch = script.Parent
local hitpart = punch.HitPart
local anim = punch:WaitForChild("Animations")
local remote = punch:WaitForChild("Remote")
local char = game.Players.LocalPlayer.Character
local lhum = char:FindFirstChildOfClass("Humanoid")
local loadswing = lhum:LoadAnimation(anim:WaitForChild("Swing1"))
local loadidle = lhum:LoadAnimation(anim:WaitForChild("Idle"))
local sound = punch:WaitForChild("SwingSound")
local equipped = false

punch.Equipped:Connect(function(mouse)

	equipped = true
	loadidle:Play()

	punch.Unequipped:Connect(function()

		equipped = false

		if loadswing then

			loadswing:Stop()

		end

		loadidle:Stop()

	end)

end)

punch.Activated:Connect(function()

	if punch.Enabled == true and equipped == true then

		loadswing:Play()
		local invoke = remote:InvokeServer("Swing")

		if invoke == true then

			loadswing.KeyframeReached:Connect(function(name)

				if name == "Sound" then

					sound:FireServer()

				end

			end)

		end

	end

end)

And here is script ( idk for what)

local debounce = false

function getPlayer(humanoid) 
local players = game.Players:children() 
for i = 1, #players do 
if players[i].Character.Humanoid == humanoid then return players[i] end 
end 
return nil 
end 

function onTouch(part) 

local human = part.Parent:findFirstChild("Humanoid") 
if (human ~= nil) and debounce == false then

debounce = true

local player = getPlayer(human) 

if (player == nil) then return end 

script.Parent:clone().Parent = player.Backpack

wait(2)
debounce = false
end
end


script.Parent.Parent.Touched:connect(onTouch) 

So this is the tool? That copy script should have worked outā€¦
As for this script I hate working on things I canā€™t test. Best I can do is a rewright guess.

local punch = script.Parent
local hitpart = punch.HitPart
local anim = punch:WaitForChild("Animations")
local remote = punch:WaitForChild("Remote")
local player = game:GetService("Players").LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local lhum = char:WaitForChild("Humanoid")
local sound = punch:WaitForChild("SwingSound")
local equipped = false
local loadswing, loadidle

punch.Equipped:Connect(function(mouse)
    equipped = true
    loadswing = lhum:LoadAnimation(anim:WaitForChild("Swing1"))
    loadidle = lhum:LoadAnimation(anim:WaitForChild("Idle"))
    loadidle:Play()

    punch.Unequipped:Connect(function()
        equipped = false
        if loadswing then
            loadswing:Stop()
        end
        if loadidle then
            loadidle:Stop()
        end
    end)
end)

punch.Activated:Connect(function()
    if punch.Enabled and equipped then
        loadswing:Play()
        local invoke = remote:InvokeServer("Swing")

        if invoke == true then
            loadswing.KeyframeReached:Connect(function(name)
                if name == "Sound" then
                    sound:FireServer()
                end
            end)
        end
    end
end)

Really like how this works tooā€¦

local player = game:GetService("Players").LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local lhum = char:WaitForChild("Humanoid")

Both of these are the best ways to get Player and Character, I think.
One for server one for client. Humanoid is needed here for timing.
Even if I donā€™t use it in the codeā€¦ I will use it for the stall for a lock.
Works better than charloaded.

It looks like your server script is set up to give weapons to players when they join. Ensure that the onCharacterAdded and onPlayerAdded functions are correctly initializing and assigning tools:

local weaponsFolder = game.ServerStorage:WaitForChild("Weapons")
local weapons = weaponsFolder:GetChildren()

local function giveWeapons(player)
    local backpack = player:WaitForChild("Backpack")
    if backpack then
        for _, weapon in ipairs(weapons) do
            local clone = weapon:Clone()
            clone.Parent = backpack
        end
    end
end

local function onCharacterAdded(character)
    local player = game.Players:GetPlayerFromCharacter(character)
    if player then
        task.wait(0.1)
        giveWeapons(player)
    end
end

local function onPlayerAdded(player)
    player.CharacterAdded:Connect(onCharacterAdded)
    if player.Character then
        giveWeapons(player)
    end
end

game.Players.PlayerAdded:Connect(onPlayerAdded)

Ensure that the tool script correctly handles the toolā€™s behavior and interactions:

local punch = script.Parent
local remote = punch.Remote
local hitpart = punch.HitPart
local humanoidlist = {}
local touch
local debris = game:GetService("Debris")
local Players = game:GetService("Players")
local cooldownTime = 3

function CheckHumanoid(hum)
    for _, v in pairs(humanoidlist) do
        if v == hum then
            return true
        end
    end
    return false
end

-- Additional functions to manage tool behavior

punch.Equipped:Connect(function()
    local char = punch.Parent
    print("Punch equipped by:", char.Name)
    initialize(char)
end)

Players.PlayerAdded:Connect(function(player)
    player:SetAttribute("CooldownActive", false)
    player.CharacterAdded:Connect(function(character)
        task.wait(1)
        if punch.Parent ~= character then
            print("Re-parenting punch to character's right arm.")
            punch.Parent = character:FindFirstChild("Right Arm")
        end
        initialize(character)
    end)
end)

Make sure the client script manages animations and interactions correctly:

local punch = script.Parent
local hitpart = punch.HitPart
local anim = punch:WaitForChild("Animations")
local remote = punch:WaitForChild("Remote")
local char = game.Players.LocalPlayer.Character
local lhum = char:FindFirstChildOfClass("Humanoid")
local loadswing = lhum:LoadAnimation(anim:WaitForChild("Swing1"))
local loadidle = lhum:LoadAnimation(anim:WaitForChild("Idle"))
local sound = punch:WaitForChild("SwingSound")
local equipped = false

punch.Equipped:Connect(function(mouse)
    equipped = true
    loadidle:Play()
    punch.Unequipped:Connect(function()
        equipped = false
        if loadswing then
            loadswing:Stop()
        end
        loadidle:Stop()
    end)
end)

punch.Activated:Connect(function()
    if punch.Enabled == true and equipped == true then
        loadswing:Play()
        local invoke = remote:InvokeServer("Swing")
        if invoke == true then
            loadswing.KeyframeReached:Connect(function(name)
                if name == "Sound" then
                    sound:FireServer()
                end
            end)
        end
    end
end)

Summary

  • Ensure tools are correctly initialized and assigned.
  • Check the parenting of tools to the playerā€™s character or backpack.
  • Verify event connections are properly managed.

If you still encounter issues, please provide more details or screenshots to help further diagnose the problem.

Hope this helps!

Doesnā€™t work, when I joined from alt account, several weapons are diappeared