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

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

Asked by 5 years ago

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
You need to use { } to define a table not (). User#5423 17 — 5y

1 answer

Log in to vote
0
Answered by
ee0w 458 Moderation Voter
5 years ago
Edited 5 years ago

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!
0
thx it helped but my character still wont lay the animation when i press q lord_lol123 3 — 5y
0
sorry my mistake i disable the punch script haha my bad lord_lol123 3 — 5y
Ad

Answer this question