Here's the script (btw its in a tool as a local script) what it's meant to do is when you press q and you have a certain amount of a stat then it will trigger a punch animation
math.randomseed(tick()) local player = game.Players.LocalPlayer local char = game.Workspace:FindFirstChild(player.Name) local RS = game.ReplicatedStorage local StatsFolder = game.ReplicatedStorage:WaitForChild("StatsFolder") local ReplicatedStorage = game:GetService("ReplicatedStorage") local punchEvent = Instance.new("RemoteEvent", ReplicatedStorage) punchEvent.Name = "PunchEvent" local animations = {1083459730, 1083486387} --Must be changed because the animations made by me won't work for other people than me. Make your own and insert the id's here, separated by commas. local function onPunchFired(player) if RS.StatsFolder:FindFirstChild(char.Name).Fat.Value > 10 or RS.StatsFolder:FindFirstChild(char.Name).Muscle.Value > 10 then local humanoid = char.Humanoid local animation = Instance.new("Animation") local picked = math.random(1, #animations) animation.AnimationId = "http://roblox.com/asset/?id="..animations[picked] local animTrack = humanoid:LoadAnimation(animation) animTrack:Play() local dmgScript = script.DmgScript:Clone() if picked == 1 then dmgScript.Parent = char.RightHand elseif picked == 2 then dmgScript.Parent = char.LeftHand end dmgScript.Disabled = false wait(0.4) dmgScript:Destroy() end end punchEvent.OnServerEvent:Connect(onPunchFired) ---------------
Your error is coming about because the player's character hasn't loaded yet. One simple solution is to continue to wait until the player has a character:
local char = player.Character while not char do wait() char = player.Character end
Other notes:
math.random()
after initializing the randomseed
Closed as Non-Descriptive by hiimgoodpack, XAXA, abnotaddable, chess123mate, Thundermaker300, and Goulstem
This question has been closed because its title or content does not adequately describe the problem you are trying to solve.
Please ensure that your question pertains to your actual problem, rather than your attempted solution. That is, you were trying to solve problem X, and you thought solution Y would work, but instead of asking about X when you ran into trouble, you asked about Y.
Why was this question closed?