#Scripting For The First Time. Trying To Code An Attack, Help?

1 messages · Page 1 of 1 (latest)

sweet osprey
#

Good Evening, fellow Developers! I'm coding for the first time (Attempting to Code a Battleground Game and I'm honestly stuck and confused where I went wrong. I followed along with a video I'll send in the description very closely to get ideas of how to begin coding.

Data Handler

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(Player)
for _, v in script.PlayerValues:GetChildren() do
v:Clone().Parent = Player
end
end)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Events = ReplicatedStorage.Events

local AttackHitboxes = require(script.Parent.AttackHitboxes)

local ClickAttackDebounces = {}

Events.ClickAttack.OnServerEvent:Connect(function(Player)
local Character = Player.Character
if Character == nil then
return
end
local Humanoid = Character:FindFirstChild("Humanoid")
if Humanoid == nil then
return
end
if Humanoid.Health > 0 then

end

end)

Server Attack Handler

local Humanoid = Character:FindFirstChild("Humanoid")
if not Humanoid then return end
if Humanoid.Health <= 0 then return end

if ClickAttackDebounces[Player] then return end
ClickAttackDebounces[Player] = true 

local PunchCombo = Player.Value.PunchCombo
local Animation = script.PunchAnimationCycles:FindFirstChild(tostring(PunchCombo.Value))
if not Animation then 
    ClickAttackDebounces[Player] = nil
    return 
end    

local Animator = Humanoid:FindFirstChild("Animator")
if not Animator then 
    ClickAttackDebounces[Player] = nil
    return 
end

local LoadedPunchAnimation = Animator:LoadAnimation(Animation)
LoadedPunchAnimation:Play()

if PunchCombo.Value >= #script.PunchAnimationCycles:GetChildren() then
    PunchCombo.Value = 1
else 
    PunchCombo.Value += 1
end

task.wait(LoadedPunchAnimation.Length + 0.1)
ClickAttackDebounces[Player] = nil 

end)

#

Didn't let me send the last bits so following up here

Click Attacks

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")

local Events = ReplicatedStorage:WaitForChild("Events")

local Character = script.Parent.Parent

local IsBlocking = false

UserInputService.InputBegan:Connect(function(Input, GameProcessedEvents)
if GameProcessedEvents then return end

if Input.UserInputType == Enum.UserInputType.MouseButton1 and not IsBlocking then
    Events.ClickAttack:FireServer()
end

if Input.KeyCode == Enum.KeyCode.F then
    IsBlocking = true
    Events.Block:FireServer(true)
end

end)

UserInputService.InputEnded:Connect(function(Input, GameProcessedEvent)
if Input.KeyCode == Enum.KeyCode.F then
IsBlocking = false
Events.Block:FireServer(false)
end
end)

And this is the video I was watching https://www.youtube.com/watch?v=E02er6mwsrI

How To Make a BATTLEGROUNDS GAME In Roblox Studio 2024

Get all of my project files on my patreon:
https://bit.ly/3SOBP6J
JOIN THE DISCORD!
https://discord.gg/cztJHYSfVE
UI Model:
https://bit.ly/3VT9QFW

What is Roblox? ROBLOX is an online virtual playground and workshop, where kids of all ages can safely interact, create, have fun, and learn. ...

▶ Play video
zealous kelp
#

whats the issue?

zealous kelp
#

i think you declared the events folder instead of the actual RemoveEvent

sweet osprey
#

Would I be allowed to send an image of how the files are structured? Is that allowed?

zealous kelp
#

yes

sweet osprey
#

m1

zealous kelp
#

could you send the files in replicatedstorage

sweet osprey
#

Yeah please give me a second I closed it on the right and am trying to figure out how to reopen it. Sorry I'm really new to this, me and my friend just started learning/

zealous kelp
#

take your time im an s0 on rsc im unemployed lol

sweet osprey
crisp musk
sweet osprey
vast dirgeBOT
#

studio** You are now Level 1! **studio

zealous kelp
#

first of all "Clicl Attack", second of all replace Events in #1413781598062776432 message to:
local AttackEvent = ReplicatedStorage:WaitForChild("Events"):FindFirstChild("Click Attack")

#

hold up disregard the 2nd

#

i couldnt read without codeblock

crisp musk
vast dirgeBOT
#

studio** You are now Level 8! **studio

sweet osprey
#

Thank you guys I feel like an idiot for mispelling it lol 😭

crisp musk
crisp musk
#

And spaces do matter

sweet osprey
#

Data Handler

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(Player)
for _, v in script.PlayerValues:GetChildren() do
v:Clone().Parent = Player
end
end)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local AttackEvent = ReplicatedStorage:WaitForChild("Events"):FindFirstChild("Click Attack") = ReplicatedStorage.Events

local AttackHitboxes = require(script.Parent.AttackHitboxes)

local ClickAttackDebounces = {}

local AttackEvent = ReplicatedStorage:WaitForChild("Events"):FindFirstChild("Click Attack").ClickAttack.OnServerEvent:Connect(function(Player)
local Character = Player.Character
if Character == nil then
return
end
local Humanoid = Character:FindFirstChild("Humanoid")
if Humanoid == nil then
return
end
if Humanoid.Health > 0 then

end

end)

#

Server Attack Handler

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local AttackEvent = ReplicatedStorage:WaitForChild("Events"):FindFirstChild("Click Attack")ReplicatedStorage:WaitForChild("Events")
local AttackHitboxes = require(script.Parent.AttackHitboxes)

local ClickAttackDebounces = {}

local AttackEvent = ReplicatedStorage:WaitForChild("Events"):FindFirstChild("Click Attack").ClickAttack.OnServerEvent:Connect(function(Player)
local Character = Player.Character
if not Character then return end

local Humanoid = Character:FindFirstChild("Humanoid")
if not Humanoid then return end
if Humanoid.Health <= 0 then return end

if ClickAttackDebounces[Player] then return end
ClickAttackDebounces[Player] = true 

local PunchCombo = Player.Value.PunchCombo
local Animation = script.PunchAnimationCycles:FindFirstChild(tostring(PunchCombo.Value))
if not Animation then 
    ClickAttackDebounces[Player] = nil
    return 
end    

local Animator = Humanoid:FindFirstChild("Animator")
if not Animator then 
    ClickAttackDebounces[Player] = nil
    return 
end

local LoadedPunchAnimation = Animator:LoadAnimation(Animation)
LoadedPunchAnimation:Play()

if PunchCombo.Value >= #script.PunchAnimationCycles:GetChildren() then
    PunchCombo.Value = 1
else 
    PunchCombo.Value += 1
end

task.wait(LoadedPunchAnimation.Length + 0.1)
ClickAttackDebounces[Player] = nil 

end)

#

Click Attacks

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")

local AttackEvent = ReplicatedStorage:WaitForChild("Events"):FindFirstChild("Click Attack") = ReplicatedStorage:WaitForChild("Events")

local Character = script.Parent.Parent

local IsBlocking = false

UserInputService.InputBegan:Connect(function(Input, GameProcessedEvents)
if GameProcessedEvents then return end

if Input.UserInputType == Enum.UserInputType.MouseButton1 and not IsBlocking then
    local AttackEvent = ReplicatedStorage:WaitForChild("Events"):FindFirstChild("Click Attack").ClickAttack:FireServer()
end

if Input.KeyCode == Enum.KeyCode.F then
    IsBlocking = true
    local AttackEvent = ReplicatedStorage:WaitForChild("Events"):FindFirstChild("Click Attack").Block:FireServer(true)
end

end)

UserInputService.InputEnded:Connect(function(Input, GameProcessedEvent)
if Input.KeyCode == Enum.KeyCode.F then
IsBlocking = false
local AttackEvent = ReplicatedStorage:WaitForChild("Events"):FindFirstChild("Click Attack").Block:FireServer(false)
end
end)

#

Is this better? I feel like it's still a bit messy

crisp musk
#

U keep redefining the remotes each time u send them

#

And for m1s u don't wanna use waitforchild

sweet osprey
#

Is what you're talking about the find and wait for firstchild

crisp musk
#

Sorry, fireserver not fire

sweet osprey
#

OH WAIT I UNDERSTAND instead of writing the whole thing I could just write ClickLFireserver()

#

I DID IT AGAIN 😭

#

How would I type it out though. After originally defining it just saying ClickAttack:fireserver()

real topaz
#

Step 1: dont try to make a combat game if its your first time

real topaz
crisp musk
sweet osprey
#

Oh I'm just messing around with stuff for now

sweet osprey
#

Alright updated code and I'm still having some trouble with it

vast dirgeBOT
#

studio** You are now Level 2! **studio

sweet osprey
#

The goal right now is just to get the punching animation to work

sweet osprey
#

The animation simply isn't playing when I m1

#

I'm not attempting to start damage or anything of the sorts yet i just need the animation to play and it isn't

sweet osprey
#

Punch Combo is a string that i assume gives the character its animations for its punches according to the video I was watching

#

Would you like me to send you the video as that's what I've been using as a reference. Keep in mind I have no intentions of posting this game, just gaining experience

crisp musk
#

Print both Animation and Punchcombo after defining them