You can write your topic however you want, but you need to answer these questions:
I want the script to play an animation when a player sits on the seat. Also when it finds a player that sat on the seat, I also want it to spawn in a particle emitter from “SeverStorage” onto the players head.
The problem here is the animation doesn’t stop playing and the particle emitter never even spawned onto the player’s head.
i’ve tried sending a screenshot of the script onto HiddenDevs code - help. Nothing worked.
I’m a beginner scripter. Just started 2 weeks ago and I’ve got to say this is most difficult script I’ve ever done. Been stuck on it for a few days now.
-- / Service(s)
local RunService = game:GetService("RunService")
local ServerStorage = game:GetService("ServerStorage")
-- Stuff(s)
local Particle = ServerStorage:FindFirstChild("ParticleEmitter")
local Seat = script.Parent
-- AnimationsTrack(s)
local AnimTrack
-- Animation(s)
local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://13113598813"
local PrimaryPart
-- Check if the player is sitting on the seat
RunService.Heartbeat:Connect(function()
if Seat.Occupant ~= nil then
local Character = Seat.Occupant.Parent -- Get the Humanoid's/Occupant's parent or in short, just make it get the character
local Humanoid = Character:FindFirstChild("Humanoid")
PrimaryPart = Character.PrimaryPart -- Correct me if I'm wrong, but they has changed the PrimaryPart to Head now
-- If Head does not have "ParticleEmitter" then, make it have one and parent it on the head
if PrimaryPart:FindFirstChild("ParticleEmitter") == nil then
local ClonedParticle = Particle:Clone()
ClonedParticle.Parent = PrimaryPart
-- Load the animation and play it
AnimTrack = Humanoid:LoadAnimation(Animation)
AnimTrack:Play()
end
else
-- If the "AnimTrack" isn't nil then, stop the "AnimTrack" and also delete the "ParticleEmitter"
if AnimTrack ~= nil then
local specifiedParticle = PrimaryPart:FindFirstChild("ParticleEmitter")
specifiedParticle:Destroy()
AnimTrack:Stop()
end
end
end)
The child of the HumanoidObject, Animator should be used to load animations.
You do not store the particleClone, so when you try and :Destroy() it you just :Destroy() your newly created one.
Also I prefer :GetPropertyChangedSignal(...) instead of .Changed when detecting 1 property changed.
Now there are few mistakes we can gather from this also.
You try and get a child called “Head” which is parented to the Occupant
You load the animation on the Occupant not on Occupant.Animator
You :Clone() unneededly when someone stops sitting on the seat.
Instead have something like:
local playingAnim, particleClone
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
-- Stop
if playingAnim then
playingAnim:Stop() playingAnim = nil
end
if particleClone then
particleClone:Destroy()
end
-- Start
local occupant = seat.Occupant
if not occupant or not occupant.Parent then return end
local animator, head = occupant:FindFirstChildWhichIsA("Animator"), occupant.Parent:FindFirstChild("Head")
if animator then
playingAnim = occupant:LoadAnimation(newAnim)
playingAnim:Play()
end
if head then
particleClone = particleEmit:Clone()
particleClone.Parent = head
end
end)
Wow, so many mistakes.
I’m not sure but do I replace your code with the function I made? Because I did it and the animation part works but not the particle emitter. It didn’t spawned.
Make sure head is not nil.
Another issue could be that the Particle Emitter has not been Enabled. So check if the ParticleEmitter is parented to your head.