#how do i set custom humanoid attributs
88 messages · Page 1 of 1 (latest)
You can use instance attributes.
so if I understand correctly you want to add an attribute whenever the event gets fired right?
yes
to what instance do you want to add the attribute to?
wdym
like to which object to you want to add an attribute to when the event gets fired
the "playerhit" variable humanoid?
whaa
so basicly im makeing a boss fighting game and i making it so if im punching it makes a attribute true then false then when attribut true you cant punch
welp if you want to add an attribute just [humanoid]:SetAttribute(name of the attribute, Value)
so like to the player who punched the boss humanoid
[humanoid]:SetAttribute("isPunching", true)
oh ok
playerhit.Character.Humanoid:SetAttribute("IsPunching", true)
so that
i guess is what you're looking for?
this is my script
local event = game.ReplicatedStorage:WaitForChild("Hit")
local plr = game.Players.LocalPlayer
local humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
event.OnServerEvent:Connect(function(playerhit)
humanoid:SetAttribute("IsPunching", true) -- Set IsPunching attribute to true
print("IsPunching is set to true")
wait(0.3)
humanoid:SetAttribute("IsPunching", false) -- Set IsPunching attribute back to false after 0.3 seconds
print("IsPunching is set to false")
end)
so i replace that
i put it in a script though
in a serverscript?
yes
theres no localplayer for a server script
** You are now Level 10! **
ill edit the script for it to work 2 sec
ok thx
event.OnServerEvent:Connect(function(player, playerhit)
if not player.Character then return end
local humanoid = player.Character:WaitForChild("Humanoid")
humanoid:SetAttribute("IsPunching", true) -- Set IsPunching attribute to true
print("IsPunching is set to true")
wait(0.3)
humanoid:SetAttribute("IsPunching", false) -- Set IsPunching attribute back to false after 0.3 seconds
print("IsPunching is set to false")
end)```
this should work
ok thx
np
wait wanna see my punch scipt tell me if theres anything to inprove
local Cooldown = 0.3 -- Change the cooldown as needed
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local userInputService = game:GetService("UserInputService")
-- Function to check if the player is equipping any tool
local function isEquippingAnyTool()
for _, child in pairs(character:GetChildren()) do
if child:IsA("Tool") then
return true
end
end
return false
end
-- Create a function to handle the mouse click event
local function onMouseClick()
if not debounce and not isEquippingAnyTool() then
if script.Combo.Value ~= 4 then
debounce = true
humanoid.WalkSpeed = 5
game.ReplicatedStorage.Hit:FireServer(1)
wait(0.2)
wait(Cooldown)
humanoid.WalkSpeed = 16
debounce = false
elseif script.Combo.Value == 4 then
debounce = true
humanoid.WalkSpeed = 0
wait(0.5)
humanoid.WalkSpeed = 16
wait(2.4)
debounce = false
end
end
end
-- Connect the function to the mouse click event
userInputService.InputBegan:Connect(function(input, isProcessed)
if input.UserInputType == Enum.UserInputType.MouseButton1 and not isProcessed then
onMouseClick()
end
end)
You can make your isEquipping function shorter like so:
local function isEquippingAnyTool()
return (character:FindFirstChildOfClass("Tool") and true) or false
end
You could also move the debounce setter lines out of your if statements to shorten the script:
local function onMouseClick()
if not debounce and not isEquippingAnyTool() then
debounce = true
if script.Combo.Value ~= 4 then
humanoid.WalkSpeed = 5
game.ReplicatedStorage.Hit:FireServer(1)
wait(0.2)
wait(Cooldown)
humanoid.WalkSpeed = 16
elseif script.Combo.Value == 4 then
humanoid.WalkSpeed = 0
wait(0.5)
humanoid.WalkSpeed = 16
wait(2.4)
end
debounce = false
end
end
ok thx

wait how do i make it so if humanoid:SetAttribute("IsPunching", true) then it stops it from fireing Hit event
You can use an if statement to check the value with Instance:GetAttribute(key: string).
i tried but idk were to put local function onMouseClick()
if not debounce and not isEquippingAnyTool() then
debounce = true
if script.Combo.Value ~= 4 then
humanoid.WalkSpeed = 5
game.ReplicatedStorage.Hit:FireServer(1)
wait(0.3)
wait(Cooldown)
humanoid.WalkSpeed = 16
elseif script.Combo.Value == 4 then
humanoid.WalkSpeed = 0
wait(0.5)
humanoid.WalkSpeed = 16
wait(2.4)
end
debounce = false
end
end
You already have another function that calls onMouseClick when the player clicks, though.
@deft surge @mossy frigate i did it
wait
bruh
here
@mossy frigate
and @deft surge
video fps bruh bad
fr
wanna try
it
My internet is a trumped-up load of horse crap right now since I'm in a farm in the middle of nowhere.
cant sorry
ok
yo bro @mossy frigate can you help
?
function findNearestPlayer(Position)
wait(0.3)
local List = game.Workspace:children()
local Torso = nil
local Distance = 30
local Temp = nil
local char = game.Workspace.fightingdummy
local humanoid = char.Humanoid
local Human = nil
local Temp2 = nil
for x = 1, #List do
Temp2 = List[x]
if (Temp2.className == "Model") and (Temp2 ~= script.Parent) then
Temp = Temp2:findFirstChild("HumanoidRootPart")
Human = Temp2:findFirstChild("Humanoid")
if (Temp ~= nil) and (Human ~= nil) and (Human.Health > 0) then
if (Temp.Position - Position).magnitude < Distance then
Torso = Temp
Distance = (Temp.Position - Position).magnitude
end
end
end
end
return Torso
end
local followtime = 6
local starttime = tick()
local attacktime = 4
local currenttime
local char = script.Parent
local humanoid = char.Humanoid
function stopfollowing()
humanoid:Move(char.HumanoidRootPart.Position)
humanoid.WalkToPart = nil
humanoid.WalkToPoint = char.HumanoidRootPart.Position
end
while true do
local target = findNearestPlayer(script.Parent.HumanoidRootPart.Position)
if target ~= nil then
script.Parent.Humanoid:MoveTo(target.Position, target)
currenttime = tick()
if currenttime -starttime >= followtime then
wait(0.5)
stopfollowing()
wait(attacktime)
starttime = tick()
end
end
end
how do i make it so if distance is less than 5 then
function stopfollowing()
humanoid:Move(char.HumanoidRootPart.Position)
humanoid.WalkToPart = nil
humanoid.WalkToPoint = char.HumanoidRootPart.Position
end
nvm that
i solved that
i need this solved why no damage
local TS = game:GetService("TweenService")
local RS = game:GetService("ReplicatedStorage")
local SS = game:GetService("ServerStorage")
local Damage = 15
local vel
local vel2
local anim
local Modules = RS.Modules
local RockModule = require(Modules.RockModulePro)
script.Parent.OnServerEvent:Connect(function(p)
local Character = p.Character
local Humanoid = p.Character:WaitForChild("Humanoid")
local RootPart = p.Character:WaitForChild("HumanoidRootPart")
local Anim = Humanoid:LoadAnimation(script.Animation)
local Bat = RS["hammer tool"].hammer:Clone()
local Joint = RS["hammer tool"].Motor6D:Clone()
Bat.Parent = Character
Joint.Parent = Character["Right Arm"]
Joint.Part0 = Character["Right Arm"]
Joint.Part1 = Bat.WeaponHold
Anim:Play()
Humanoid.WalkSpeed = 0
Humanoid.JumpPower = 0
script.Swing:Play()
Anim:GetMarkerReachedSignal("jump"):Connect(function()
vel = Instance.new("BodyVelocity", RootPart)
vel.MaxForce = Vector3.new(1,1,1) * 1000000;
vel.Parent = RootPart
vel.Velocity = Vector3.new(1,1,1) * RootPart.CFrame.LookVector * 70 + RootPart.CFrame.UpVector * 50
vel.Name = "SmallMoveVel"
game.Debris:AddItem(vel,.1)
end)
Anim:GetMarkerReachedSignal("DMG"):Connect(function()
wait(0.1)
script.Hit:Play()
wait(0.1)
local hitbox = Instance.new("Part", workspace.Hitbox)
hitbox.CanCollide = false
hitbox.CanTouch = true
hitbox.Anchored = true
hitbox.Name = "Hitbox"
hitbox.Material = Enum.Material.ForceField
hitbox.Size = Vector3.new(12,12,12)
hitbox.CanQuery = false
hitbox.Transparency = 0.7 --Edit this if you want to see the hitbox (1 is fully invisible, 0 is fully visible)
hitbox.Color = Color3.fromRGB(255, 0, 0)