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

Character not found in-game, but only studio, HELP?

Asked by 7 years ago

This problem happens from time to time. But this time, when I looked in the developer's console in-game, it said character was a nil value. It works fine in studio however. Here's the script :

player = game.Players.LocalPlayer
char = game.Players.LocalPlayer.Character
hum = game.Players.LocalPlayer.Character.Humanoid
mouse = game.Players.LocalPlayer:GetMouse()

mouse.KeyDown:Connect(function(key)
key = key:lower()
if key == "e" then
local fb = game:GetService("ServerStorage").Fireball:Clone()
game:GetService("Chat"):Chat(char.Head, "Fireball!", "Red")
fb.Parent = game.Workspace
fb.Anchored = true
if char.UpperTorso and char.LowerTorso then fb.CFrame = char.UpperTorso.CFrame + Vector3.new(0, 0, -2)
        else
    fb.CFrame = char.Torso.CFrame + Vector3.new(0, 0, -2)
end
end
end)
0
stop spamming, noob minikitkat 687 — 7y
0
@antonio6643 .-. i dont think its a client whatever crap people keep saying i think its probably the character thing Inpolite 44 — 7y

1 answer

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

First of all, you're using way too many unnecessary global variables. So, this RBX_Wiki article is something for you:

Change the first lines of your code to this:

-- LocalScript.
local Plr = game:GetService("Players").LocalPlayer
local Char = Plr.Character or Plr.CharacterAdded:wait()

And why are you trying to access the ServerStorage with a Local Script? You can't access it on the client!

You're welcome,

soved

Ad

Answer this question