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

Can someone help with connecting client to server using FireServer()?

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!")

1 answer

✓ Accepted answer

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")

4 comments

0

I have fixed it. It was because I didn't add the RemoteEvent itself to call the server script. Also, That was the first thing I had tried, and the error I had with that was that it could potentially yield forever if I didn't add a value to it, so I put 2, Now I am trying to figure out why the damage part of the script isn't working. But thank you for the help!

0

Nice! I'm glad you figured it out.

0

Do a search in models for thienbao2109 - his FE Gun Kit is pretty good! Its one of the best I've come across - great examples and features.

0

Thanks for the advice!

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