I’m making it so you can swap between guns in a tutorial area. Problem is, the guns will swap, but will keep the animations will go crazy, go silent, and will give me this:
(game.StarterPlayer.StarterCharacterScripts.LocalHandler) The script with issues:
local UserInputService = game:GetService("UserInputService")
local RepStore = game:GetService("ReplicatedStorage")
local ViewModel = RepStore:WaitForChild("Viewmodel")
local mouse = game.Players.LocalPlayer:GetMouse()
local SpringMod = require(RepStore.SpringModule)
local UIdisable = RepStore:WaitForChild("DeactivateUI")
local recSpring = SpringMod.new()
local bobSpring = SpringMod.new()
local swaySpring = SpringMod.new()
local MainModule = require(RepStore.MainModule)
local Arms = RepStore:WaitForChild("Arms")
local GiveGun = RepStore:WaitForChild("GiveGun")
local DestroyVM = RepStore:WaitForChild("DestroyVM")
local Stepped
local Clickdet
DestroyVM.Event:Connect(function()
game.Workspace:WaitForChild("Camera"):WaitForChild("Viewmodel"):Destroy()
Stepped:Disconnect()
end)
Arms.Event:Connect(function()
TrueModel = ViewModel:Clone()
print("e")
TrueModel.Parent = game.Workspace.Camera
Stepped = game:GetService("RunService").RenderStepped:Connect(function(dt)
MainModule.update(TrueModel, dt, recSpring, bobSpring, swaySpring)
end)
end)
GiveGun.Event:Connect(function(GunModel)
pcall(function()
if Clickdet.Connected then
Clickdet:Disconnect()
end
print("disconnected!")
end)
print(GunModel)
local AnimationsFolder = RepStore:WaitForChild(GunModel.."Animations")
local GunModel = RepStore:WaitForChild(GunModel):Clone()
TrueModel = game.Workspace.Camera:FindFirstChild("Viewmodel")
if TrueModel:FindFirstChildWhichIsA("Model") then
TrueModel:FindFirstChildWhichIsA("Model"):Destroy()
end
MainModule.weldgun(GunModel)
MainModule.animate(TrueModel, AnimationsFolder.Hold)
print("e")
print(GunModel.Name.." "..TrueModel.Name)
TrueModel.Parent = game.Workspace.Camera
MainModule.equip(TrueModel, GunModel)
MainModule.animate(TrueModel, AnimationsFolder.Hold)
local CanFire = true
if GunModel.Name == "StarterPistol" then
Delayy = 0.5
Range = 50
elseif GunModel.Name == "LaserRifle" then
Delayy = 0.25
Range = 100
end
Clickdet = game:GetService("RunService").RenderStepped:Connect(function(dt)
mouse.Button1Down:Connect(function()
if CanFire then
CanFire = false
recSpring:shove(Vector3.new(3, 0, 0))
MainModule.cast(GunModel.Components.Barrel.Position, GunModel.Name, mouse.Hit.Position,Range)
wait(Delayy)
CanFire = true
end
end)
end)
end)