This is the 3rd time posting it. Sorry if it annoys you, I just need to fix this problem.
It is essentially the Hitbox
, which is a 3d shape (typically a box), used to determine when/what is hitting it, so for a sword either the blade or an invisible part that represents the “kill zone”, if that makes sense.
so how do I put that into a code basically?
It’s a basepart, so just get a part already on the sword that can act as a hitbox, or make one, then set the variable to that basepart.
oh I dont have to add more codes after hitbox =
?
Incase if you are wondering what problem I have, I am trying to build a system that lets you get cash if you kill someone with classic sword. However, there are some problems I need to fix, and I need more info about it so I can understand what is going on.
(WARNING! I tried to put ` each line and obviously it didnt work. Try reading carefully if you can!)
Here is a script on the sword:
local hitbox = – part that hits playres
hitbox.Touched:Connect(function(hitPart)
local hitChar = hitPart:FindFirstAncestorOfClass("Model") -- get the character model that was hit
local char = hitbox:FindFirstAncestorOfClass("Model") -- get the character of the player holding the sword, you can use this because the tool is moved into the player character when it is equipped
if not hitChar:FindFirstChild("Humanoid") then
return
end
local hitPlayer = game.Players:GetPlayerFromCharacter(hitChar) -- get the hitted player instance
local player = game.Players:GetPlayerFromCharacter(char)
hitPlayer.Killer.Value = player -- even if the player doesn't die set the killer so that you can know who killed the player once they die
end)
Here is the Sword script from free model (Sorry for too much):
Tool = script.Parent
Handle = Tool:WaitForChild(“Handle”)
function Create(ty)
return function(data)
local obj = Instance.new(ty)
for k, v in pairs(data) do
if type(k) == ‘number’ then
v.Parent = obj
else
obj[k] = v
end
end
return obj
end
end
local BaseUrl = “rbxassetid://”
Players = game:GetService(“Players”)
Debris = game:GetService(“Debris”)
RunService = game:GetService(“RunService”)
DamageValues = {
BaseDamage = 5,
SlashDamage = 10,
LungeDamage = 30
}
–For R15 avatars
Animations = {
R15Slash = 522635514,
R15Lunge = 522638767
}
Damage = DamageValues.BaseDamage
Grips = {
Up = CFrame.new(0, 0, -1.70000005, 0, 0, 1, 1, 0, 0, 0, 1, 0),
Out = CFrame.new(0, 0, -1.70000005, 0, 1, 0, 1, -0, 0, 0, 0, -1)
}
Sounds = {
Slash = Handle:WaitForChild(“SwordSlash”),
Lunge = Handle:WaitForChild(“SwordLunge”),
Unsheath = Handle:WaitForChild(“Unsheath”)
}
ToolEquipped = false
–For Omega Rainbow Katana thumbnail to display a lot of particles.
for i, v in pairs(Handle:GetChildren()) do
if v:IsA(“ParticleEmitter”) then
v.Rate = 20
end
end
Tool.Grip = Grips.Up
Tool.Enabled = true
function IsTeamMate(Player1, Player2)
return (Player1 and Player2 and not Player1.Neutral and not Player2.Neutral and Player1.TeamColor == Player2.TeamColor)
end
function TagHumanoid(humanoid, player)
local Creator_Tag = Instance.new(“ObjectValue”)
Creator_Tag.Name = “creator”
Creator_Tag.Value = player
Debris:AddItem(Creator_Tag, 2)
Creator_Tag.Parent = humanoid
end
function UntagHumanoid(humanoid)
for i, v in pairs(humanoid:GetChildren()) do
if v:IsA(“ObjectValue”) and v.Name == “creator” then
v:Destroy()
end
end
end
function Blow(Hit)
if not Hit or not Hit.Parent or not CheckIfAlive() or not ToolEquipped then
return
end
local RightArm = Character:FindFirstChild(“Right Arm”) or Character:FindFirstChild(“RightHand”)
if not RightArm then
return
end
local RightGrip = RightArm:FindFirstChild(“RightGrip”)
if not RightGrip or (RightGrip.Part0 ~= Handle and RightGrip.Part1 ~= Handle) then
return
end
local character = Hit.Parent
if character == Character then
return
end
local humanoid = character:FindFirstChildOfClass(“Humanoid”)
if not humanoid or humanoid.Health == 0 then
return
end
local player = Players:GetPlayerFromCharacter(character)
if player and (player == Player or IsTeamMate(Player, player)) then
return
end
UntagHumanoid(humanoid)
TagHumanoid(humanoid, Player)
humanoid:TakeDamage(Damage)
end
function Attack()
Damage = DamageValues.SlashDamage
Sounds.Slash:Play()
if Humanoid then
if Humanoid.RigType == Enum.HumanoidRigType.R6 then
local Anim = Instance.new("StringValue")
Anim.Name = "toolanim"
Anim.Value = "Slash"
Anim.Parent = Tool
elseif Humanoid.RigType == Enum.HumanoidRigType.R15 then
local Anim = Tool:FindFirstChild("R15Slash")
if Anim then
local Track = Humanoid:LoadAnimation(Anim)
Track:Play(0)
end
end
end
end
function Lunge()
Damage = DamageValues.LungeDamage
Sounds.Lunge:Play()
if Humanoid then
if Humanoid.RigType == Enum.HumanoidRigType.R6 then
local Anim = Instance.new("StringValue")
Anim.Name = "toolanim"
Anim.Value = "Lunge"
Anim.Parent = Tool
elseif Humanoid.RigType == Enum.HumanoidRigType.R15 then
local Anim = Tool:FindFirstChild("R15Lunge")
if Anim then
local Track = Humanoid:LoadAnimation(Anim)
Track:Play(0)
end
end
end
--[[
if CheckIfAlive() then
local Force = Instance.new("BodyVelocity")
Force.velocity = Vector3.new(0, 10, 0)
Force.maxForce = Vector3.new(0, 4000, 0)
Debris:AddItem(Force, 0.4)
Force.Parent = Torso
end
]]
wait(0.2)
Tool.Grip = Grips.Out
wait(0.6)
Tool.Grip = Grips.Up
Damage = DamageValues.SlashDamage
end
Tool.Enabled = true
LastAttack = 0
function Activated()
if not Tool.Enabled or not ToolEquipped or not CheckIfAlive() then
return
end
Tool.Enabled = false
local Tick = RunService.Stepped:wait()
if (Tick - LastAttack < 0.2) then
Lunge()
else
Attack()
end
LastAttack = Tick
–wait(0.5)
Damage = DamageValues.BaseDamage
local SlashAnim = (Tool:FindFirstChild(“R15Slash”) or Create(“Animation”){
Name = “R15Slash”,
AnimationId = BaseUrl … Animations.R15Slash,
Parent = Tool
})
local LungeAnim = (Tool:FindFirstChild("R15Lunge") or Create("Animation"){
Name = "R15Lunge",
AnimationId = BaseUrl .. Animations.R15Lunge,
Parent = Tool
})
Tool.Enabled = true
end
function CheckIfAlive()
return (((Player and Player.Parent and Character and Character.Parent and
Humanoid and Humanoid.Parent and Humanoid.Health > 0 and Torso and
Torso.Parent) and true) or false)
end
function Equipped()
Character = Tool.Parent
Player = Players:GetPlayerFromCharacter(Character)
Humanoid = Character:FindFirstChildOfClass("Humanoid")
Torso = Character:FindFirstChild("Torso") or Character:FindFirstChild("HumanoidRootPart")
if not CheckIfAlive() then
return
end
ToolEquipped = true
Sounds.Unsheath:Play()
end
function Unequipped()
Tool.Grip = Grips.Up
ToolEquipped = false
end
Tool.Activated:Connect(Activated)
Tool.Equipped:Connect(Equipped)
Tool.Unequipped:Connect(Unequipped)
Connection = Handle.Touched:Connect(Blow)
Here is a localscript of my gui that shows cash:
local plr = game.Players.LocalPlayer
local Stats = plr:FindFirstChild("stats")
script.Parent.Text = Stats.Money.Value
Stats.Money.Changed:Connect(function(NewValue)
script.Parent.Text = NewValue
end)
And lastly here is a script from ServerScriptService:
game.Players.PlayerAdded:Connect(function(plr)
local Stats = Instance.new("Folder")
Stats.Name = "stats"
Stats.Parent = plr
local Money = Instance.new("IntValue")
Money.Name = "Money"
Money.Value = 0
Money.Parent = Stats
plr.Character:WaitForChild("Humanoid"):connect(function(killed)
local CreatorTag = plr.Character.Humanoid:FindFirstChild("creator")
if CreatorTag and CreatorTag.Value then
local stats = CreatorTag.Value:WaitForChild("leaderstats")
stats.Money.Value = stats.Money.Value + 20
end
end)
end)
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
local humanoid = char:WaitForChild("Humanoid")
local killer = Instance.new("ObjectValue")
killer.Name = "Killer"
killer.Parent = player
humanoid.Died:Connect(function()
if killer.Value then
killer.Value = nil -- reset the killer value so that if the player dies again the last player who killed him doesn't get the cash
killer.Value.Cash.Value += 100
end
end)
end)
end)
I hope this contributes a lot to you and I hope I can get this problem fixed soon. Thanks for helping!
So…
What’s the issue with the code.
Also try using Ctrl + E
on an empty line to have a clean area for code. (Also try using the Hide details
tool, by clicking over the gear icon and selecting it)
An example
This text will be hidden, like long code
-- Lots of code
-- Even more code!
And,
Why haven’t you set a hitbox, what do you mean by:
Because I have said, it is a basePart, in this case either a Part, MeshPart (read up on CollisionFidelity), or a WedgePart (Typically not used however).
The First script appears to be normal, but has a couple of “Issues”:
-
The Variable
stats
appears to be looking forleaderstats
, and notStats
which is the name of your Folder. -
Your Quotes (Strings) are not being recognized by the script which are supposed to be
red
inside this Lua Code block, but are just plaingrey
Should be fixed here:
game.Players.PlayerAdded:Connect(function(plr)
local Stats = Instance.new("Folder")
Stats.Name = "stats"
Stats.Parent = plr
local Money = Instance.new("IntValue")
Money.Name = "Money"
Money.Value = 0
Money.Parent = Stats
plr:WaitForChild("Humanoid").Died:connect(function(killed)
local CreatorTag = plr.Humanoid:FindFirstChild("creator")
local Killer = CreatorTag.Value
if CreatorTag and Killer then
local stats = Killer:WaitForChild("stats") -- Possibly the issue
stats.Money.Value += 20
end
end)
end)
stats
isnt a Good name in this Script Because there is a Variable already named Stats
which can be confusing, plus, you can accidentally change it to something else.
LocalScript: (if you want your Cash to Appear a UI)
local Plr = game.Players.LocalPlayer
while task.wait() do -- so it constantly updates
["Your TextLabel Here"].Text = Plr:WaitForChild("stats").Money.Value
end
so what should I switch into instead of stats?
Dont switch anything, your script is fine, just create a LicalScript and get the Players Cah Value and make the Text Assign it as its Text
Breaking this down, I will put the local script in the gui so it will show how much cash I have right? Making sure this is what I am supposed to do sorry.
Yes, If you want to show how much you have, you can do that
alright so I put this into a new local script and there is an error here
How do I fix this problem?
Sorry for the delay I was busy
change [Your TextLabel Here]
with the textGui you want to change
Alright so I tried every possible way to fix this like [0]
and [TextLabel]
and it still didnt work. I think its the script on the sword or possibly the script in the serverscriptservice
oh and the first part of [
had an error and idk how to fix it
As i stated, remove it and replace it with the TextLabel you want to use:
For Example:
Plr = game.Players.LocalPlayer
TextLabel = script.Parent.TextLabel
while task.wait() do
TextLabel.Text = Plr:WaitForChild("stats").Money.Value
end
ah so I got to get rid of [ ] right?
yes
Char limitt
Okay I put that in but still not working. I might have put it in a separate local script in the TextLabel. If thats wrong, I am going to combine them together. Otherwise, If I replace it, the text wont show up.