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

how do i fix attempt to get length of upvalue 'animations' (a number value)?

my script

math.randomseed(tick())

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local punchEvent = Instance.new("RemoteEvent", ReplicatedStorage)
punchEvent.Name = "PunchEvent"

local animations = (2729957815)

local function onPunchFired(plr)
	local char = game.Workspace:FindFirstChild(plr.Name)
	local humanoid = char.Humanoid
	local animation = Instance.new("Animation")
	animation.AnimationId = "http://roblox.com/asset/?id="..animations[math.random(1, #animations)]
	local animTrack = humanoid:LoadAnimation(animations)
	animTrack:Play()
end

punchEvent.OnServerEvent:Connect(onPunchFired)

the error

20:28:03.324 - ServerScriptService.Punch:13: attempt to get length of upvalue 'animations' (a number value)

how do i fix this plss help

1 comment

1

You need to use { } to define a table not ().

1 answer

✓ Accepted answer

Silly mistake you made. You did this:

local animations = (2729957815)

Which gets evaluated as

local animations = 2729957815

Therefore, animations is a number value. When you try to index it later on, it throws an error.

20:28:03.324 - ServerScriptService.Punch:13: attempt to get length of upvalue 'animations' (a number value)

To fix this, do what kingdom5 said and replace your () with {} or curly brackets. This tells Lua that you're making a table.

######If I helped, be sure to upvote/accept!

2 comments

0

thx it helped but my character still wont lay the animation when i press q

0

sorry my mistake i disable the punch script haha my bad

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