I am trying to make a combat system,and have heard that the best way to do so is by making the server deal the damage/magnitude while the client does the animations, sounds, etc. However, when I try to use :FireServer() with it to connect the client to the server, it doesn't work. The error I always receive is "51: attempt to index upvalue 'ServerCombat' (a nil value)"
local ReplicatedStorage = game:GetService("ReplicatedStorage") local ServerCombat = ReplicatedStorage:WaitForChild("ServerCombat", 2) local UserInputService = game:GetService("UserInputService") -- A counter to help decide which animation to play local swingCount = 0 local swingCount2 = 0 local currentSwingAnimation --Animation for the Light attack combo sequence. UserInputService.InputBegan:connect(function(Input, IsTyping) if IsTyping then return end
if Input.KeyCode == Enum.KeyCode[Key] and Debounce then swingCount = swingCount + 1 -- cancel any animation currently playing if currentSwingAnimation then currentSwingAnimation:Stop() currentSwingAnimation = nil end if swingCount == 1 then -- play the first animation Debounce = false local Animation = Instance.new("Animation") Animation.AnimationId = AnimationId1 currentSwingAnimation = Humanoid:LoadAnimation(Animation) currentSwingAnimation.Looped = false currentSwingAnimation:Play() Humanoid.WalkSpeed = 0 Humanoid.JumpPower = 0 ServerCombat:FireServer() wait(.35) currentSwingAnimation:Stop() Debounce = true Humanoid.WalkSpeed = 16 Humanoid.JumpPower = 50 elseif swingCount == 2 then -- play the second swing animation Debounce = false local Animation = Instance.new("Animation") Animation.AnimationId = AnimationId2 currentSwingAnimation = Humanoid:LoadAnimation(Animation) currentSwingAnimation.Looped = false currentSwingAnimation:Play() Humanoid.WalkSpeed = 0 Humanoid.JumpPower = 0 wait(.35) currentSwingAnimation:Stop() Debounce = true Humanoid.WalkSpeed = 16 Humanoid.JumpPower = 50 print("Working!")
Try taking the 2 out of your WaitForChild - you may not be giving it enough time to load and find the object in ReplicatedStorage.
local ServerCombat = ReplicatedStorage:WaitForChild("ServerCombat")