I’m trying to make a fighting game using keybinds instead of tools, but I keep running into the same problems when it comes down to animation and coding.
There are two knives welded to the player (one on the back and one on the arm) and I want to have one vanish and the other appear in the middle of the animation to give a seamless transition that makes it looks like they just take it off their waist. I’ve been able to accomplish this effect already but the issue is that it only appears on the client.
What the player sees:
What others see:
I used a Local Script in StarterCharacterScripts, and yes I know that is probably what’s causing the problem, I just don’t know any other way to tackle this issue and I’ve looked everywhere for a way to solve this problem.
local UIS = game:GetService("UserInputService")
local humanoid = script.Parent:WaitForChild("Humanoid")
local attackEquip = humanoid:LoadAnimation(script.attackequipAnim)
local weapon = script.Parent:WaitForChild("Right Arm"):WaitForChild("knifewep").WeaponModel
local prop = script.Parent:WaitForChild("KitchenKnife")
local equipped = false
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.E then
if not equipped then
equipped = true
attackEquip:Play()
attackEquip:GetMarkerReachedSignal("swap"):Connect(function()
weapon.Transparency = 0
prop.Transparency = 1
end)
end
end
end)
You can see why this is an issue when you take a look at Roblox’s Client Server mode (Client-Server Runtime | Documentation - Roblox Creator Hub). Each client individually has its own control over what it sees, whereas the server replicates to everyone.
What you’re doing only individually replicates to your client, as you can see yourself.
To fix this, you need to do a few things, which can be broken down into a few problems:
You need to use a server script, which is run on the server. This presents a problem because you cannot access anything that the client would see, like UserInputService, or the LocalPlayer, which again is only accessible on the Client. This is where RemoteEvents come in. RemoteEvents are used to communicate between the server and client (or in reverse order). Remote Events and Callbacks | Documentation - Roblox Creator Hub. You can have your client script communicate to the server that you’re starting the animation, and the server will change the transparency of your knife object:
And ka-boom, you’ve got yourself a working animation system!
Let me know if you have any questions. But I recommend reading both guides I attached.
I thought it would have something with Remote Events and things such as that, I just haven’t done much work with them, but now it works as intended for all players.