Script is in proximity prompt in a part in workspace
When the prompt is triggered I keep getting this error
Workspace.Trees.Tree.Trunk.ProximityPrompt.Script:2: attempt to index nil with ‘Character’
local function onPromptTriggered(promptObject, player)
local character = player.Character
if character then
local humanoid = character:WaitForChild("Humanoid")
local animation = game:GetService("InsertService"):LoadAsset(humanoid.Animations.SideSwipe)
local animationTrack = humanoid:LoadAnimation(animation)
animationTrack:Play()
animationTrack.Stopped:Connect(function()
animation:Destroy()
end)
end
end
script.Parent.Triggered:Connect(onPromptTriggered)
The Triggered event only passes the player through. Remove the promptObject variable in the function and it should work.
local function onPromptTriggered(player)
local character = player.Character
if character then
local humanoid = character:WaitForChild("Humanoid")
local animation = game:GetService("InsertService"):LoadAsset(humanoid.Animations.SideSwipe)
local animationTrack = humanoid:LoadAnimation(animation)
animationTrack:Play()
animationTrack.Stopped:Connect(function()
animation:Destroy()
end)
end
end
script.Parent.Triggered:Connect(onPromptTriggered)