so i made a gun with a tool with out the requires handle, it works but when the local player die it say that the hold animaton it isnt a valid member
robloxapp-20210307-1136151.wmv (4,2 MB)
i tried to change the name, i was thinking it was the problem
here how it looks like in the explorer (client side,tool)
here is the local script
local canshoot = true
local isreloading = false
local noammotime = true
local holding = false
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local tool = script.Parent
local actionService = game:GetService("ContextActionService")
local idleAnim = char:WaitForChild("Humanoid"):LoadAnimation(script.Hold)
local shootAnim = char:WaitForChild("Humanoid"):LoadAnimation(script.Recoil)
local reloadAnim = char:WaitForChild("Humanoid"):LoadAnimation(script.Reload)
local emptyanim = char:WaitForChild("Humanoid"):LoadAnimation(script.empty)
local shootEff = tool.Hole.shoot
local equipeff = tool.Hole["Equip sound"]
local reloadeff = tool.Hole["Reload Sound"]
local emptyeff = tool.Hole.EmptySound
local variables = tool.VALues
local ammo = variables.ammo
local playerGui = plr:WaitForChild("PlayerGui")
local show_ammo = playerGui["show ammo"]
local function reload()
local canreload = true
if holding == true and isreloading == false then
wait()
isreloading = true
canreload = false
reloadAnim:Play()
reloadeff:Play()
wait(3)
isreloading = false
ammo.Value = 30
canreload = true
end
end
tool.Equipped:Connect(function()
show_ammo.Enabled = true
actionService:BindAction("Reload", reload, true, Enum.KeyCode.R)
actionService:SetPosition("Reload", UDim2.new(0.58, 0,0.15, 0))
actionService:SetTitle("Reload", "reload")
local mouse = game.Players.LocalPlayer:GetMouse()
mouse.Icon = "http://www.roblox.com/asset?id=117431027"
game.ReplicatedStorage.ConnectM6D:FireServer(tool.BodyAttach)
char.UpperTorso.ToolGrip.Part0 = char.UpperTorso
char.UpperTorso.ToolGrip.Part1 = tool.BodyAttach
idleAnim:Play()
equipeff:Play()
holding = true
while wait() do
show_ammo.TextLabel.Text = "ammo: "..ammo.Value
end
end)
tool.Unequipped:Connect(function()
show_ammo.Enabled = false
actionService:UnbindAction("Reload")
local mouse = game.Players.LocalPlayer:GetMouse()
mouse.Icon = "http://www.roblox.com/asset?id=5801470647"
game.ReplicatedStorage.DisconnectM6D:FireServer()
idleAnim:Stop()
equipeff:Play()
holding = false
end)
tool.Activated:Connect(function()
if isreloading == false and ammo.Value > 0 and canshoot == true then
wait()
ammo.Value = ammo.Value - 1
canshoot = false
shootAnim:Play()
shootEff:Play()
wait(1)
canshoot = true
elseif ammo.Value == 0 and noammotime == true then
local playerGui = plr:WaitForChild("PlayerGui")
playerGui["no ammo"].Enabled = true
noammotime = false
emptyeff:Play()
emptyanim:Play()
wait(3)
noammotime = true
playerGui["no ammo"].Enabled = false
end
end)
here how it looks like in the explorer (server side,serverscriptservice)
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local M6D = Instance.new("Motor6D")
M6D.Name = "ToolGrip"
M6D.Parent = char.UpperTorso
end)
end)
game.ReplicatedStorage.ConnectM6D.OnServerEvent:Connect(function(plr, location)
local char = plr.Character
char.UpperTorso.ToolGrip.Part0 = char.UpperTorso
char.UpperTorso.ToolGrip.Part1 = location
end)
game.ReplicatedStorage.DisconnectM6D.OnServerEvent:Connect(function(plr)
plr.Character.UpperTorso.ToolGrip.Part1 = nil
end)
here ishow it looks like