Hello, I was trying to do a weapon that can equip and activate another tool when right-clicking. The script works for me on studio but when I try it in the real game, it equips the tool but doesnt do anything. Here's my script:
local v = game.Players.LocalPlayer local vm = v:GetMouse() local w = script.Parent.Parent:WaitForChild("Bomb") local t = script.Parent local used = false t.Equipped:Connect(function(Mouse) Mouse.Button2Down:connect(function() if not used then used = true t.AutoEquip.Disabled = true v.Character.Humanoid:EquipTool(w) wait(0.1) w:Activate() game.Workspace:WaitForChild("TimeBomb"..v.Name) t.AutoEquip.Disabled = false wait(5) used = false end end) end)
Everything is in the explorer place it should be. In the real game console, it returns: Attempt to index a nil value
Thanks
LocalPlayer
is nil
on the server, so to fix this simply make your Script
a LocalScript
. I also tidied up your code a bit. Please remember to put your code in code blocks, by clicking the blue Lua icon and pasting the code in between the tildes.-- Local Script!! And please have good variable names local player = game.Players.LocalPlayer local mouse = player:GetMouse() local bomb = script.Parent.Parent:WaitForChild("Bomb") local tool = script.Parent local used = false tool.Equipped:Connect(function(Mouse) Mouse.Button2Down:Connect(function() -- :connect is deprecated, use :Connect if not used then used = true tool.AutoEquip.Disabled = true player.Character.Humanoid:EquipTool(bomb) wait(0.1) bomb:Activate() game.Workspace:WaitForChild("TimeBomb"..player.Name) tool.AutoEquip.Disabled = false wait(5) used = false end end) end)