of     1   

Never2Humble
#228317025Saturday, December 02, 2017 5:17 AM GMT

Hello, I've got a problem with my weapon script. It's the AlvinBlox 3 hour long video gun tutorial-style weapon. When the weapon is inside the StarterPack, it works just fine, but if its cloned from ReplicatedStorage, it doesn't fire. The error I receive is for this function, in a ServerScriptStorage script on the third line: function checkBodyType(player,tool) if game.Workspace[player.Name]:FindFirstChild("LowerTorso") then --For R15 models tool.shoot.AnimationId = "rbxassetid://123456789" tool.reload.AnimationId = "rbxassetid://123456789" return "R15" end The error is: "attempt to index local 'tool' (a nil value) I'm not sure why the script works fine if its a StarterPack tool, but fails on that specific line if its cloned from ReplicatedStorage. Any thoughts?
little5
#228317073Saturday, December 02, 2017 5:19 AM GMT

This isn't the entire script, but from what I can tell, you aren't passing in a tool object when invoking the function.
Never2Humble
#228317349Saturday, December 02, 2017 5:34 AM GMT

little5 - The entire script is rather long, I thought this would be easier, let me paste an abridged version. The error is down towards the bottom in that last function: function checkBodyType(player,tool) This script is inside ServerScriptStorage and fires after a weapon is equipped: --Variables local serverStorage = game:GetService("ServerStorage") local replicatedStorage = game:GetService("ReplicatedStorage")["Ranged"]["Gun"] --Weapon portion, aiming,trajectory, damage, etc., no errors here replicatedStorage.EquipAnimation.OnServerEvent:Connect(function(player,animation) local newAnim = game.Workspace[player.Name].Humanoid:LoadAnimation(animation) newAnim:Play() replicatedStorage.UnequipAnimation.OnServerEvent:Connect(function(player,animation) newAnim:Stop() for i,v in pairs(game.Workspace:GetChildren()) do if v.Name == player.Name.."'s Trajectory" then v:Destroy() end end end) replicatedStorage.Reload.OnServerEvent:Connect(function(player,animation) newAnim:Stop() local reloadAnim = game.Workspace[player.Name].Humanoid:LoadAnimation(animation) reloadAnim:Play() wait(1) reloadAnim:Stop() end) end) function checkBodyType(player,tool) if game.Workspace[player.Name]:FindFirstChild("LowerTorso") then -- R15 tool.shoot.AnimationId = "r######################### to####################### "r######################### return "R15" end if game.Workspace[player.Name]:FindFirstChild("Torso") then -- R6 tool.shoot.AnimationId = ######################### tool.reload.AnimationId = ######################### return "R6" end end replicatedStorage.CheckBodyType.OnServerInvoke = checkBodyType
Never2Humble
#228317366Saturday, December 02, 2017 5:35 AM GMT

^ The hashtagged part is just the animation ID #, the error is on that "tool.shoot.AnimationId" part.
little5
#228317388Saturday, December 02, 2017 5:36 AM GMT

And the client will invoke this?
Never2Humble
#228317482Saturday, December 02, 2017 5:40 AM GMT

Yep, got the RemoteEvents and RemoteFunctions for it. If the tool is inside the StarterPack, no problem whatsoever. It's only when its cloned from the ReplicatedStorage to the Backpack - like for a custom inventory, that it gives that error. This is my custom inventory script that happens when a player clicks the button in their inventory: Item1.MouseButton1Click:connect(function() local tool = game:GetService("ReplicatedStorage").Gun:Clone() tool.Parent = p.Backpack end) The weapon then appears in their backpack, it can be equipped, but it doesn't fire, getting hung on that animationID error line.
little5
#228317524Saturday, December 02, 2017 5:42 AM GMT

I would need to see the client script in order to see what tool is being defined as
Never2Humble
#228317594Saturday, December 02, 2017 5:45 AM GMT

This is the full local script inside the Tool: local tool = script.Parent -- Getting the tool local player = game:GetService("Players").LocalPlayer -- Getting the player local mouse = player:GetMouse() -- Getting the mouse local sound = tool:WaitForChild("Gunfire") local torso = "" -- Nothing for now. local reloading = false -- Variable to check if we are currently reloading local contextActionService = game:GetService("ContextActionService") -- Allow us to cater for Mobile players local bodytype = nil -- Nil for now but will check whether player is R6 or R15 local difference = 0 -- Difference between position of head and mouse local replicatedstorage = game:GetService("ReplicatedStorage").Ranged.GunRemotes local gungui = tool:WaitForChild("GunGUI") local bullets = tool:WaitForChild("Bullets") local reloadtime = 1 -- Remote Events local equipAnimation = replicatedstorage:WaitForChild("EquipAnimation") local headshot = replicatedstorage:WaitForChild("Headshot") local reload2 = replicatedstorage:WaitForChild("Reload") local shootevent = replicatedstorage:WaitForChild("ShootEvent") local unequipanimation = replicatedstorage:WaitForChild("UnequipAnimation") -- Remote Functions local checkBodyType = replicatedstorage:WaitForChild("CheckBodyType") local fetchBulletsLeft = replicatedstorage:WaitForChild("FetchBulletsLeft") -- Find Body Type function findBodyType() -- Used to determine whether a player is R6 or R15 bodytype = checkBodyType:InvokeServer(tool) -- Invoking the Remotefunction to do a check on the server print(bodytype) end -- Reloading function function reload() reloading = true reload2:FireServer(tool.reload) mouse.Icon = "h########################################## player.PlayerGui:WaitForChild("GunGUI").Bullets.Text = "Recharging!" wait(reloadtime) bullets.Value = 6 player.PlayerGui:WaitForChild("GunGUI").Bullets.Text = "Bullets: "..bullets.Value -- REWORD THIS FOR MAGIC POINTS mouse.Icon = "http://www.roblox.com/asset?id=936803874" equipAnimation:FireServer(tool.shoot) reloading = false end -- When the tool is equipped, the following event will run tool.Equipped:Connect(function(mouse) gungui:Clone().Parent = player.PlayerGui -- We are cloning the Gun GUI into the player's PlayerGUI findBodyType() -- Calling the function above to check the body type. equipAnimation:FireServer(tool.shoot) -- Calling the equip animation remoteevent so that the server can play the animation mouse.Icon = "h########################################## mouse.Button1Down:Connect(function() if bullets.Value <=0 or reloading == true then -- Don't do anything else local head = game.Workspace[player.Name].Head.CFrame.lookVector local mouse = CFrame.new(game.Workspace[player.Name].Head.Position,mouse.Hit.p).lookVector difference = (head-mouse) local ra### #a##################################################### tool.Handle.CFrame.p).unit*300) -- Last number is how many studs the bullet will travel. local part,position = game.Workspace:FindPartOnRay(ray,player.Character,false,true) sound:Play() if difference.magnitude < 1.33 then shootevent:FireServer(tool,position,part) bullets.Value = bullets.Value - 1 end end end) local reloadMobileButton = contextActionService:BindAction("ReloadBtn",reload,true,"r") contextActionService:SetPosition("ReloadBtn",UDim2.new(0.72,-25,0.20,-25)) co#####################################################################################- CHANGE THIS IF YOU WANT TO CHANGE THE RELOAD BUTTON FOR MOBILE. end) tool.Unequipped:Connect(function() mouse.Icon = "" unequipanimation:FireServer(tool.shoot) player.PlayerGui.GunGUI:Destroy() contextActionService:UnbindAction("ReloadBtn") end) headshot.OnClientEvent:Connect(function() player.PlayerGui.GunGUI.Headshot:TweenPosition(UDim2.new(0.5,-100,0.5,-25), "Out","Quint",0.3) wait(1.5) player.PlayerGui.GunGUI.Headshot:TweenPosition(UDim2.new(-1,0,0.5,-25), "In","Quint",0.4) wait(0.5) player.PlayerGui.GunGUI.Headshot.Position = UDim2.new(1.5,0,0.5,-25) end) The other script in the previous post is the ServerScriptStorage script that's being called on.
Never2Humble
#228333665Saturday, December 02, 2017 5:45 PM GMT

Bump, anyone else have any thoughts? I know it has to be something silly that's causing this. Why else would it be okay for the animation to work when its in StarterPack, but not when cloned from Replicated Storage into Backpack?

    of     1