Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Radstar1 270 Moderation Voter
7 years ago
Edited 7 years ago

[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

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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!

0
Thank you so much, I also found out that putting everything as local when the Parent was already local messed things up. Radstar1 270 — 7y
Ad
Log in to vote
1
Answered by 7 years ago
Edited 7 years ago

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

0
It helped indexed character, but whenever it tries to refer to humanoid inside the character, it says he model isn't available. Radstar1 270 — 7y
0
Thank you also though, this helped part of the problem. Radstar1 270 — 7y

Answer this question