So, I was making a game with someone and we did put a keybind and when we press it, it punchs.
local debounce = false
local canGetKnocked = true
local UIS = game:GetService("UserInputService")
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://11358584487"
local Animation2 = Instance.new("Animation")
Animation2.AnimationId = "rbxassetid://11358352743"
local dizzy1 = Instance.new("Animation")
dizzy1.AnimationId = "rbxassetid://11361130166"
local dizzy2 = Instance.new("Animation")
dizzy2.AnimationId = "rbxassetid://11361123987"
UIS.InputBegan:Connect(function(Input, isTyping)
if isTyping then return end
local keyPressed = Input.KeyCode
if keyPressed == Enum.KeyCode.E then
if debounce == false then
debounce = true
print("It's fine")
local LoadAnimation = char.Humanoid:LoadAnimation(Animation)
LoadAnimation:Play()
local LoadAnimation2 = char.Humanoid:LoadAnimation(Animation2)
LoadAnimation2:Play()
local Arms = script.Parent:WaitForChild("Left Arm") or script.Parent:WaitForChild("Right Arm")
Arms.CanCollide = false
Arms.Touched:Connect(function(hit)
if canGetKnocked then
canGetKnocked = false
local otherHum = hit.Parent:WaitForChild("Humanoid")
local dizzyAnim = otherHum:LoadAnimation(dizzy1)
dizzyAnim:Play()
local dizzyAnim2 = otherHum:LoadAnimation(dizzy2)
dizzyAnim2:Play()
workspace.Stars.Position = hit.Parent:FindFirstChild("Head").Position + Vector3.new(0, 2, 0)
wait(4)
workspace.Stars.Position = Vector3.new(0, -100, 0)
canGetKnocked = true
end
end)
wait(4)
debounce = false
end
end
end)
This is the code and when we press “E”, the punch animation is working and both players can see it but when the dizzy animation is supposed to be playing for both, it’s only playing for the player that played animation… Can someone help me?
Only animations will run for both players if they are using server defined instances for the character that are replicated: e.g your default limbs. To workaround this you would want to continue playing the animation on client and then fire a User specific remote handler for animations e.g “VellianRemote” to the server and then fireclient to every other player with the information of: Play animation for Target Character
Player Joins game, Ok lets create a Remote event for this player and store it in a folder in replicatedstorage. We also need to connect this event so in the playeradded we apply myEvent.OnServerEvent connect ( function ( targetplayer)
if TargetPlayer == player then we allow this to run
If Argument == AnimationVisualRequest then
we have another event which fires clients called “AnimationHandler” or something.
Then in a localscript we handle this .OnClientEvent with the parameters being the Desired character and Desired animation to play on
You cannot load animations onto another humanoid through your client and have them replicate to other players.
You’ll need to use a remote event to “tell” the other client that they have to play that animation.
Also, just to fix a problem you probably havent encountered yet:
Loading animations onto the Humanoid is depracated. Load them onto the animator instead. Humanoid.Animator:LoadAnimation()
Im also going to add on, DO NOT load animations every time they get played.
Animators and Humanoids have a loaded animation limit of 256 animations, and will not load any more after that number is reached, so essentially, when youve punched 256 times, you will not see the animation again until your character resets.
Instead, you should load animations once into a table, and then call them from the table when required.