Hello! right now i’m making a horror game, the 1st scene takes place in a Gas Station. & i’m facing a problem where the Animation for “Thinking to buy” for an NPC called “Grandpa” only loops on the Server’s Side, & not the Client’s Side. how do i fix this? thanks!
(sorry if this post is in the wrong category)
Grandpa's Script
--MAIN VARS
local npc = script.Parent
local primaryPart = npc.PrimaryPart
local humanoid = npc.Humanoid
local animations = require(script.Animations).animations
animations.thinking:Play()
--DEBOUNCE
local thinkingLoop = true
local eventDb = false
--SERVICES
local tweenService = game:GetService("TweenService")
local replicatedStorage = game:GetService("ReplicatedStorage")
--EVENTS
local uv = replicatedStorage.UninvitedVisitor
local events = uv.Events
local dialog = events.Dialog
local dialogRepeat = events.NpcDialogueRepeat
--FUNCTIONS
local function getClosestPlayer()
local closestPlayer, closestDistance = nil, 8
local players = game:GetService("Players"):GetPlayers()
for _, player in players do
local character = player.Character
if character and character:FindFirstChild("HumanoidRootPart") then
local distance = (primaryPart.Position - character.HumanoidRootPart.Position).Magnitude
if distance < closestDistance then
closestPlayer = player
closestDistance = distance
thinkingLoop = false
if eventDb == false then
eventDb = true
dialog:FireAllClients(npc, "GRANDPA")
end
end
end
end
return closestPlayer
end
while true do
local plr = getClosestPlayer()
if plr then
if thinkingLoop == false then
tweenService:Create(primaryPart, TweenInfo.new(1), {CFrame = CFrame.lookAt(primaryPart.Position, plr.Character.HumanoidRootPart.Position)}):Play()
animations.thinking:Stop()
end
end
task.wait(0.001)
end
Module Script with Animations
local humanoid = script.Parent.Parent.Humanoid
local animator = humanoid.Animator;
local module = {
animations = {
idle = animator:LoadAnimation(animator.GrandpaIdle);
walking = animator:LoadAnimation(animator.GrandpaWalk);
thinking = animator:LoadAnimation(animator.GrandpaThinking);
grabbing = animator:LoadAnimation(animator.GrandpaGrabbing);
}
}
module.animations.idle.Looped = true
module.animations.walking.Looped = true
module.animations.thinking.Looped = true
return module