Trying to make a script that will weld a boombox tool on the player’s back, but it doesn’t work.
Everytime I equip, unequip and equip the tool again, it does this:
I have tried looking for solutions here, didn’t anything working for me.
Script:
local Tool = script.Parent
local Handle = Tool:WaitForChild("Handle")
local Remote = Tool:WaitForChild("Remote")
local Sound = Handle:WaitForChild("Sound")
local Player = Tool.Parent.Parent
local Character = Player.Character
function Unequipped()
local character = Player.Character
if character then
local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
if humanoidRootPart then
local weld = Handle:FindFirstChild("Weld")
if not weld then
weld = Instance.new("Weld")
weld.Name = "Weld"
weld.Parent = Handle
end
weld.Part0 = humanoidRootPart
weld.Part1 = Handle
end
end
end
function Equipped()
for i,v in ipairs(Tool:GetChildren()) do
if v:IsA("Weld") then
v:Destroy()
end
end
end
function onActivate()
Remote:FireClient(getPlayer(), "ChooseSong")
end
function getPlayer()
return game:GetService("Players"):GetPlayerFromCharacter(Tool.Parent)
end
function playSong(id)
id = id or ""
if Sound then
Sound:Destroy()
end
Sound = Instance.new'Sound'
Sound.Parent = Handle
Sound.Volume = 0.4
Sound.Looped = true
Sound.PlayOnRemove = false
Sound.SoundId = "http://www.roblox.com/asset/?id="..id
Sound.Name = "Sound"
Sound:Play()
end
function onRemote(player, func, ...)
if player ~= getPlayer() then return end
if func == "Activate" then
onActivate(...)
end
if func == "PlaySong" then
playSong(...)
end
end
Remote.OnServerEvent:connect(onRemote)
Tool.Unequipped:Connect(Unequipped)
Tool.Equipped:Connect(Equipped)