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

My script where ur arm gets hardened works in studio but not in game.. Why does this happen?

Asked by
xVanc -1
8 years ago
Edited 8 years ago

This does not work in game but in studio it works perfectly.. Idk what's wrong I've tried many solutions but idk...

BTW, ITS A LOCALSCRIPT.

PROBLEM: When I check in game logs I see something about the data model (client log)

"attempt to index local "char"

PLZ HELP!

01Players = game.Players.LocalPlayer
02mouse = Players:GetMouse()
03local char = Players.Character
04local torso = char:findFirstChild("Torso")
05local leftarm = char:findFirstChild("Left Arm")
06 
07enabled = true
08 
09function onKeyDown(key)
10    key = key:lower()
11    if key == 'q' then
12        local part = char["Left Arm"]:Clone()
13        part.BrickColor = BrickColor.new("Institutional white")
14        part.Material = "Neon"
15        part.Name = "LeftArm2"
View all 38 lines...
0
You have to include your error, otherwise, we cannot help you. crywink 419 — 8y
0
uhh someone helped me already so.... xVanc -1 — 8y

1 answer

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
8 years ago
Edited 8 years ago

Localscripts on the client can load prior to the actual character model loading, making line 4 error because 'char' is nil.. Try using a repeat loop to wait until the Character has loaded.

1local Players = game.Players.LocalPlayer
2local mouse = Players:GetMouse()
3 
4repeat wait() until Players.Character --Wait until char has loaded
5 
6local char = Players.Character
7local torso = char:findFirstChild("Torso")
8local leftarm = char:findFirstChild("Left Arm")
0
Thank u so much i appreciate the help! xVanc -1 — 8y
1
Why use lower-cased "f" on "findFirstChild"? I though that was deprecated.. FiredDusk 1466 — 8y
0
thought* FiredDusk 1466 — 8y
0
Just used it cause he used it. But yeah, it's deprecated. Goulstem 8144 — 8y
Ad

Answer this question