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

How do I make my animation for every player in the server rather than the local player?

Button = script.Parent
local replicatedstorage = game:GetService("ReplicatedStorage")
local rokaevent = replicatedstorage.Roka
local transparency = replicatedstorage.TransparencyPucci
local transparency1 = replicatedstorage.TransparencyPucciDisable
local cd = false

Button.MouseButton1Click:Connect(function()
	local plr = game.Players.LocalPlayer
	local char = plr.Character
	local hum = char.Humanoid
	
	hum.WalkSpeed = 0
hum.JumpPower = 0
	script.Parent.Parent.Parent.Parent.Parent.Character.Torso.CFrame = CFrame.new(2931.025, 127.176, -158.614)
	if cd == true then return end
	cd = true
	transparency:FireServer()
	script.Parent.Parent.Parent.Parent.RokaGUI.Enabled = false
	game.Workspace.Pucci.Stand["Stand Head"].Summon.Playing = true
	local plr = game.Players.LocalPlayer
	local chr = plr.Character
	local stand = chr:WaitForChild("Stand")
	local hum = char.Humanoid
	local hum = game.Workspace.Pucci.Stand.Humanoid
	stand:Destroy()
	
	local anim = Instance.new("Animation")
anim.AnimationId = "http://www.roblox.com/asset/?id=5251592082"

	local playAnim = hum:LoadAnimation(anim)
	playAnim:Play()
	wait(0.45)
	game.Workspace.Pucci.Stand["Stand Head"].Steal.Playing = true
	wait(1.3)
	transparency1:FireServer()
	wait(1.2)
	game.Workspace.Pucci.Stand["Stand Head"].Steal.Playing = false
	rokaevent:FireServer()
end)

Basically, the animation only shows for the local player, i need it to show for the whole server. I've tried anything possilbe but am unable to, script is a local script obviously. And fixes?

1 answer

✓ Accepted answer

In order to make everyone see an action you need to pass an action to the server side. Local scripts only affect one players game as it is only touching on the data of one computer. Roblox offers two services in order to connect the clients to the server: Remove functions and remote events.

Info about this services from the official Roblox docs: https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events

Either way to sum it up, the best way to show an animation is to send the data of the player ID and animation ID to the server and then compile the animation within the server side.

A little example (I did not test it nor use Roblox studio anymore so it may have a syntax error):

Client Side (local script):


--Wait until the game ends loading
repeat wait() until game:IsLoaded()

--Get the service (this decreases the chances of having a time error)
local replicatedStorage = game:GetService('ReplicatedStorage')

--Get the remote event 
local RemoveEventAnimation = replicatedStorage.RemoteEvent

--Animation ID
local AnimID = 41241;


--Sends the info to the server
RemoveEventAnimation:FireServer(AnimID)

Server Side (Server script):


--Location of the remove event + the event
script.Parent.RemoteEvent.OnServerEvent:Connect(function(player, animID)
	
	local playerid = player.UserId
	
	--Place your animation code here and use the playerid and anim id parameters
	--I dont really remember how animations work in roblox but it should be the
	--same way as you did it in the client side	
	
end)

I know this is a little bit hard to get at first but this is how u over all connect the clients to the server in pretty much every game engine, not just roblox and its extremly important to understand

3 comments

0

So i'll need to create a seperate remote in order for other players to see the animation?

0

What the remote event does is connect a local script to a server script. Whatever happens on a local script only the player who has it will see, whatever happens on a server script everyone will see. You use the local script to get data that only local scripts can get (playerID, UI buttons etc) and then send that data to a server script to do an action with it

0

Right, thanks!

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