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
7 years ago
Edited 7 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!

Players = game.Players.LocalPlayer
mouse = Players:GetMouse()
local char = Players.Character
local torso = char:findFirstChild("Torso")
local leftarm = char:findFirstChild("Left Arm")

enabled = true

function onKeyDown(key)
    key = key:lower()
    if key == 'q' then
        local part = char["Left Arm"]:Clone()
        part.BrickColor = BrickColor.new("Institutional white")
        part.Material = "Neon"
        part.Name = "LeftArm2"
        part.CFrame = leftarm.CFrame
        part.Anchored = true
        part.CanCollide = false
        wait()
        part.Parent = char
        for i = 1, 10 do
            part.Size = part.Size +Vector3.new(0.1,0.1,0.1)
            part.Transparency = part.Transparency + 0.1
            part.CFrame = leftarm.CFrame
            wait()
        end
        part:destroy()
        torso.Anchored = true
        leftarm.BrickColor = BrickColor.new('Really black')
        leftarm.Material = 'Neon'
        leftarm.Reflectance = 0.1
        torso.Anchored = false
    end
end

enabled = false

mouse.KeyDown:connect(onKeyDown)
0
You have to include your error, otherwise, we cannot help you. crywink 419 — 7y
0
uhh someone helped me already so.... xVanc -1 — 7y

1 answer

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
7 years ago
Edited 7 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.

local Players = game.Players.LocalPlayer
local mouse = Players:GetMouse()

repeat wait() until Players.Character --Wait until char has loaded

local char = Players.Character
local torso = char:findFirstChild("Torso")
local leftarm = char:findFirstChild("Left Arm")
0
Thank u so much i appreciate the help! xVanc -1 — 7y
1
Why use lower-cased "f" on "findFirstChild"? I though that was deprecated.. FiredDusk 1466 — 7y
0
thought* FiredDusk 1466 — 7y
0
Just used it cause he used it. But yeah, it's deprecated. Goulstem 8144 — 7y
Ad

Answer this question