[https://gyazo.com/c207b5db9ccde45bf2f29cbbf335f4ef] --Picture of Console error Does anyone know the reason why char isn't being indexed correctly? Game is FilteringEnabled, but it didn't work when it wasn't either.
local Tool = script.Parent local play = game.Players.LocalPlayer local mouse = play:GetMouse() local char = play.Character local hum = char.Humanoid local en = true Tool.Activated:connect(function() if not en then return end en = false Tool.RemoteEvent:FireServer(mouse.Hit) wait(2) en = true end)
This is an addition to Programical's Answer So there's a few ways to fix this, but I'll show how I'd fix it.
local Tool = script.Parent local play = game.Players.LocalPlayer local mouse = play:GetMouse() local char = play.Character or play.CharacterAdded:wait() -- As Programical suggested. local hum = char:WaitForChild("Humanoid") -- This will basically do what play.CharacterAdded:wait() does, but with Humanoid or anything outside of Character or Player. ... Otherwise you'd use PlayerAdded:wait() (Don't do that. Ever.) or CharacterAdded:wait() local en = true Tool.Activated:connect(function() if not en then return end en = false Tool.RemoteEvent:FireServer(mouse.Hit) wait(2) en = true end)
If this helped, be sure to let me know!
I think your script might run before the character has time to load. I found this on the Roblox wiki:
local character = player.Character or player.CharacterAdded:wait()
http://wiki.roblox.com/index.php?title=API:Class/Player/Character