Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Animation only runs on client side, How would I make this Animation run from server side?

Right now I have an animation that works! Except when I join in game with myself (from another acc) and play the animation, the other account doesn't see it. Which means its only playing from the client side and not the server. I tried a remote event but that's just too confusing for me right now. This is a localscript inside of StarterCharacterScripts

--LocalPlayer's Camera
local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera
local character = player.Character

--Crouch Animation
local mouse = player:GetMouse()
local Animate 
local Humanoid = player.Character:FindFirstChild('Humanoid')
local CrouchAnimation = game.StarterPlayer.StarterPlayerScripts.Animate
		:WaitForChild("crouch"):FindFirstChild("CrouchAnim")
local AlreadyCrouched = false

mouse.KeyDown:Connect(function(Key) 
	if Key == "c" and AlreadyCrouched == false then
			Animate = Humanoid:LoadAnimation(CrouchAnimation)
			Humanoid.CameraOffset = Vector3.new(0, -1.2, -1.5)
			Animate:Play()
			AlreadyCrouched = true
			print("Crouched")
	elseif Key == "c" and AlreadyCrouched == true then
			Humanoid.CameraOffset = Vector3.new(0, 0.2, -1.5)
			Animate:Stop()
			AlreadyCrouched = false
			print("unCrouched")
	end
end)

2 answers

✓ Accepted answer

Create a RemoteEvent in ReplicatedStorage. Run this code when the dancing animation needs to play:

local RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent") -- change this to the name of the remote event

--// Code

RemoteEvent:FireServer()

Next, insert a script into ServerScriptService. You want your code to execute when a specific condition is met, but RemoteEvents have a property called OnServerEvent. Run the following code:

-- Below this, reproduce the variable of the RemoteEvent.
local RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent") -- change this to the name of the remote event

RemoteEvent.OnServerEvent:Connect(function())
	--//Code
end)

To learn more about RemoteEvents, see here and here.

Load the animation from the server, and play it from the serveror a LocalScript.. just make sure its loaded from the server

3 comments

0

How would I do this?I already have the animation in starterplayerscripts.Animate

0

Remote functions

0

*remote event

This discussion is preserved as it was. New answers, comments, and votes are closed.