Hiya, so this is meant to be a script for a custom seat animation. It works fine in a baseplate game, but moving it to the main game with a custom animations script, it doesn’t work and is simply the default sit animation. Could someone please help me figure it out?
local seat = script.Parent
local lastOc
seat.Changed:Connect(function(prop)
if prop == "Occupant" then
if seat.Occupant then
local oc = seat.Occupant
local anim = script.Parent.Animation.AnimationId
oc.Parent.Animate.sit.SitAnim.AnimationId = anim
lastOc = oc
end
if not seat.Occupant then
if lastOc then
lastOc.Parent.Animate.sit.SitAnim.AnimationId = "http://www.roblox.com/asset/?id=6570257930"
end
end
end
end)
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
Is the “custom animations script” something that is only in the main place or was this tested in the Baseplate as well? Based on the wording in the OP, it sounds like the default Animate script was used for the baseplate but this was not the case for the main game.
Additionally, I would recommend against using the Changed event to detect when the Occupant property changes, as the event will be activated under more circumstances that it needs to. You could instead utilize the GetPropertyChangedSignal method on the property to activate a function whenever that property in specific is changed.
Here’s a slight rewrite using that in addition to additional checks to ensue the code doesn’t error if the circumstances aren’t correct:
seat:GetPropertyChangedSignal("Occupant"):Connect(function() -- Activates function whenever the Occupant property changes
local Occupant = seat.Occupant
if Occupant then -- If there's an Occupant, then...
local Animate = oc.Parent:FindFirstChild("Animate") -- Ensures the Animation LocalScript exists
local anim = script.Parent.Animation.AnimationId
if Animate then -- Updates AnimationId if Animate LocalScript exists
Animate.sit.SitAnim.AnimationId = anim
end
else -- In any other situation/whenever there isn't an Occupant
if lastOc then -- Checks if there was a previous Occupant
local Animate = lastOc.Parent:FindFirstChild("Animate") -- Ensures the Animation LocalScript exists
if Animate then -- Updates AnimationId if Animate LocalScript exists
Animate.sit.SitAnim.AnimationId = "http://www.roblox.com/asset/?id=6570257930"
end
end
end
end)
Inside of your seat add a script and an animation. Set the Id on your animation to your seat anim. Inside the script put this code
Seat = script.Parent
function added(child)
If (child.className==“Weld”) then
human = child.part1.Parent:FindFirstChild(“Humanoid”)
if human ~= nil then
anim = human:LoadAnimtaion(seat.seatAnim) seatAnim is what I called my animation
anim:Play()
end
end
end
function removed(child2)
if anim ~= nil then
anim:Stop()
anim:Remove()
end
end
seat.ChildAdded:connect(added)
seat.ChildRemoved:connect(removed)
Sorry it’s a little messy I’m on my iPad so writing is hard.