I am trying to make my gun local script work when the player buys it or when it is picked up. It does not print anything. The script only works when its in Starterpack for some reason. I tried putting some of the locals into the tool.Equipped function but that didn’t work. I am confused.
local player = game.Players:WaitForChild("LocalPlayer")
local mouse = player:GetMouse()
local tool = script.Parent
local character = player.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild("Humanoid")
local humanoidrootpart = character:WaitForChild("HumanoidRootPart")
local canaim = false
local playerGui = player:WaitForChild("PlayerGui")
local taskgui = playerGui:WaitForChild("Task")
local canaim2 = taskgui:WaitForChild("Val")
local mb2 = false
local mb1 = false
local anim = script.Animation
tool.Equipped:Connect(function()
local Character = tool.Parent
local Humanoid = Character.Humanoid
local PlayAnim = Humanoid.Animator:LoadAnimation(anim)
canaim = true
canaim2.Value = true
print("can aim should be true")
mouse.Button2Up:Connect(function()
mb2 = false
if mb1 == false then
PlayAnim:Stop()
end
end)
mouse.Button1Down:Connect(function()
mb1 = true
if canaim == true then
PlayAnim:Play()
end
end)
mouse.Button1Up:Connect(function()
mb1 = false
if mb2 == false then
if mb2 == false then
if mb1 == false then
PlayAnim:Stop()
end
end
end
end)
mouse.Button2Down:Connect(function()
mb2 = true
if canaim == true then
PlayAnim:Play()
end
end)
end)
tool.Unequipped:Connect(function()
local Character = tool.Parent
local Humanoid = Character.Humanoid
local PlayAnim = Humanoid.Animator:LoadAnimation(anim)
canaim = false
canaim2.Value = false
PlayAnim:Stop()
end)
end)