You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I want fix this issue
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)
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)
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)
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)
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.