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

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

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)

2 comments

0

You have to include your error, otherwise, we cannot help you.

0

uhh someone helped me already so....

1 answer

✓ Accepted answer

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

4 comments

0

Thank u so much i appreciate the help!

1

Why use lower-cased "f" on "findFirstChild"? I though that was deprecated..

0

thought*

0

Just used it cause he used it. But yeah, it's deprecated.

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