Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

[Runs in Play Solo, but not the Actual Game.]?

[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)

2 answers

✓ Accepted answer

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!

1 comment

0

Thank you so much, I also found out that putting everything as local when the Parent was already local messed things up.

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

2 comments

0

It helped indexed character, but whenever it tries to refer to humanoid inside the character, it says he model isn't available.

0

Thank you also though, this helped part of the problem.

This discussion is preserved as it was. New answers, comments, and votes are closed.