so hey! it's me, some random guy who's bad at scripting, pwgth. so a bit ago, I made a question: "Why do our scripts only work for ourselves?" which a very kind person, gave us an answer on why.
so afterward, I and my friend composed brand new scripts! (which don't work) and that's why I'm here. Does anybody know what I did wrong? I put these both in starter character scripts btw.
local script:
local mouse = game.Players.LocalPlayer:GetMouse() local rep = game.ReplicatedStorage mouse.KeyDown:connect(function(key) if key=="f" then rep.Punch:FireServer() end end)
script:
local rep = game.ReplicatedStorage local animation = rep.Folder["punchy boi"] local trackanimation = nil local playability = true rep.punch.OnServerEvent:Connect(function(player) if playability == true then local plr = game.Players.LocalPlayer trackanimation = plr.Character.Humanoid:LoadAnimation (animation) trackanimation.KeyframeReached:Connect(function() print("10!") end) trackanimation:play() end end)
I highlighted the stuff I thought was important to make sure yall didn't miss out on em lol.
peace! -pwgth
This code is all over the place. Make sure the name of the thing in replicstedStorage has one constant name. In the local script I see rep.Punch and in the server-side script I see rep.punch, the names are different Second, please use waitforchild so the script doesn't throw errors and stop, things like rep:WaitForChild"Punch". Third, don't use key down, and I think it's deprecated anyway, although I could be wrong. Use UserinputService.InputBegan, it's supposedly better, also I'm pretty sure the Key name always has to be uppercase. In your script, it checks for the key "f", it's gotta be "F" or if your using user input use Enum.KeyCode.F. fourth, why in tarnation are you setting local player in a SERVERSCRIPT especially when you already HAVE the player instance!?!? It's there, "player", so use it please. Also, isn't key frame reached supposed to include the name of the key frame? Like animtrack.KeyFrameReached("Name"). I could be wrong though and it would work with the anim if it has only 1 keyframe, but please, use the name just in case you ever add more key frames to the anim in the future, it's good to think ahead, always makes coding easier.. Please learn to script before trying to script. Read forums and articles and stuff.
I hope this helps :3
You're using two local scripts in a remote event. Remote events are used for client-server communications it cannot work. If you want to communicate from client-to-client or server to server then use a RemoteFunction.
mouse.KeyDown
, cause that is deprecated.:connect
is deprecated, use:Connect
instead (with an upercase c)Client: (Place in StarterPlayer<StarterPlayerScripts or StarterCharacterScript)
local ReplicatedStorage = game.ReplicatedStorage local punch = ReplicatedStorage:WaitForChild("RemoteEvent") local UserInputService = game:GetService("UserInputService") UserInputService.InputBegan:Connect(function(input) if input.KeyCode == Enum.KeyCode.F then punch:FireServer() end end)
Server-Script: (Place in ServerScriptService or workspace)
local ReplicatedStorage = game.ReplicatedStorage local punch = ReplicatedStorage:WaitForChild("RemoteEvent") -- this is the remote event. make sure it's placed in replicatedstorage local animation = ReplicatedStorage.Folder["punchy boi"] local trackanimation = nil local playability = true punch.OnServerEvent:Connect(function(player) if playability then trackanimation = player.Character.Humanoid:LoadAnimation (animation) trackanimation.KeyframeReached:Connect(function() print("10!") end) trackanimation:Play() end end)
(I'm pretty sure this code will run, if it does or doesn't let me know!)