This script below isn’t working for some reason. I connected it to an attribute in another script. It’s below this one it uses a proximity prompt. What’s happening is that the old weapon isn’t being deleted. The new weapon isn’t cloned either.
-- Services
local RS = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local SoundService = game:GetService("SoundService")
local Debris = game:GetService("Debris")
local StarterPlayer = game:GetService("StarterPlayer")
local SS = game:GetService("ServerStorage")
-- Folders
local RSStorage = RS.Storage
local Models = RSStorage.Models
local WeaponModels = Models.Weapons
local WeaponsWeld = script.Welds.Weapons
local Events = RSStorage.RemoteEvents
local AnimationsFolder = RSStorage.Animations
local WeaponsAnimationsFolder = AnimationsFolder.Weapons
local WeaponsSounds = SoundService.SFX.Weapons
local RSModules = RSStorage.Modules
local SSModules = SS.Modules
-- Events
local WeaponsEvent = Events.WeaponsEvent
-- Modules
local SoundsModule = require(RSModules.Combat.SoundsModule)
local HelpfulModule = require (SSModules.MISC.Helpful)
-- Objects
local welds = {}
-- Animations
local RunAnimation = {StarterPlayer.StarterCharacterScripts.RunningMain.Run.AnimationId}
local WalkAnimation = {StarterPlayer.StarterCharacterScripts.Animate.walk.Walk.AnimationId}
local EquipAnims = {}
local UnEquipAnims = {}
local IdleAnims = {}
local WeaponRunAnimation = {}
local WeaponWalkAnimation = {}
local RunAnimationID = {}
-- Values
local EquipDebounce= {}
-- Main Scripting
local function ChangeWeapon(plr, char, torso)
char:SetAttribute("Equipped", false)
char:SetAttribute("Combo", 1)
char:SetAttribute("Stunned", false)
char:SetAttribute("Swing", false)
char:SetAttribute("Attacking", false)
char:SetAttribute("IsRagdoll", false)
char:SetAttribute("Iframes", false)
char.Parent = workspace.Characters
local currentWeapon = char:GetAttribute("CurrentWeapon")
local Weapon = WeaponModels[currentWeapon]:Clone()
Weapon.Parent = char
welds[plr] = WeaponsWeld[currentWeapon].IdleWeaponWeld:Clone()
welds[plr].Parent = torso
welds[plr].Part0 = torso
welds[plr].Part1 = Weapon
if Weapon:FindFirstChild("SecondWeapon") then
Weapon.SecondWeld.Part0 = char["Left Arm"]
Weapon.SecondWeld.Part1 = Weapon.SecondWeapon
end
if EquipAnims then EquipAnims[plr]:Stop() end
if IdleAnims then IdleAnims[plr]:Stop() end
if UnEquipAnims then UnEquipAnims[plr]:Stop() end
end
Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local torso = char.Torso
char:SetAttribute("CurrentWeapon", "Fists")
char.Parent = workspace.Characters
ChangeWeapon(plr,char,torso)
char:GetAttributeChangedSignal("CurrentWeapon"):Connect(function()
for i,weapons in pairs (WeaponModels:GetDescendants()) do
if char:FindFirstChild(weapons.Name) then
char:FindFirstChild(weapons.Name):Destroy()
end
end
ChangeWeapon(plr,char,torso)
end)
end)
plr.CharacterAppearanceLoaded:Connect(function(char)
for i,v in pairs(char:GetDescendants()) do
if v.Parent:IsA("Accessory") and v:IsA("Part") then
v.CanTouch = false
v.CanQuery = false
end
end
end)
end)
This is the one that controls the change weapon attribute. (Changes the Weapon)
for i, parts in pairs (workspace.ChangeWeapon:GetChildren()) do
if parts:GetAttribute("GetWeapon") then
parts.ProximityPrompt.Triggered:Connect(function(plr)
local stop = false
for i, anims in pairs (plr.Character.Humanoid.Animator:GetPlayingAnimationTracks())do
if anims.Name == "M1 (1)" or anims.Name == "M1 (2)" or anims.Name == "M1 (3)" or anims.Name == "M1 (4)" then
stop = true
end
end
if plr.Character:GetAttribute("Attacking") then stop = true end
if stop then return end
plr.Character:SetAttribute("CurrentWeapon", parts:GetAttribute("GetWeapon"))
end)
end
end