I think the error is on line 2? How do I fix this?
Workspace.Model.Sushi.Script:2: attempt to index local 'player' (a nil value)
local player = game.Players.LocalPlayer repeat wait() until player.Character ~= nil local hum = player.Character:WaitForChild("Humanoid") local animation = script.ChefAnimation local AnimTrack = hum:LoadAnimation(animation) debounce = false function onClick(click, player) repeat wait() until player.Character ~= nil local hum = player.Character:WaitForChild("Humanoid") local animation = script.ChefAnimation local AnimTrack = hum:LoadAnimation(animation) local player = game.Players:GetPlayerFromCharacter(click.Parent) local char = player.Character if debounce == false then debounce = true AnimTrack:Play() wait(2) local a = game.ServerStorage.SpringRoll:Clone() a.Parent = player.Backpack wait(10) debounce = false end end script.Parent.MouseButton1Down:connect(onClick)
The problem is, the script runs before LocalPlayer finishes loading.
local player = game.Players.LocalPlayer repeat wait() until player.Character ~= nil --player, AKA LocalPlayer, was nil when you referenced it local hum = player.Character:WaitForChild("Humanoid")
Try the following solution:
repeat wait() until game.Players.LocalPlayer local player = game.Players.LocalPlayer local Character = player:WaitForChild("Character") local hum = Character:WaitForChild("Humanoid")