generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: How to make a humanoid swing?

Previous Thread :: Next Thread 
Rangerko is not online. Rangerko
Joined: 12 Sep 2008
Total Posts: 126
05 Mar 2012 01:06 PM
I have made my own humanoid from scratch, and he holds the default ROBLOX linkedsword. I was wondering how I can make him swing the sword when he gets close to a player?

I found a model that does just that...
http://www.roblox.com/Sword-bot-item?id=68050058

But I couldn't find any code inside of that model that makes him swing the sword, simulating clicking mouse button 1 or left click.
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
05 Mar 2012 01:09 PM
Didn't someone already make this?
Report Abuse
xvgigakid is not online. xvgigakid
Joined: 22 Jun 2008
Total Posts: 4407
05 Mar 2012 01:10 PM
Take a LinkedSword,
Put it inside your character

Now the linked sword is swung when the MouseButton1 goes down. All you have to do is change this line,

mouse.Button1Down:connect(SwingSword)
to
while true do
wait(3)
SwingSword()
end
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
05 Mar 2012 01:12 PM
Lol, sorry creator. I thought you meant you were the first to make this :l

Where was I? :l
Report Abuse
Rangerko is not online. Rangerko
Joined: 12 Sep 2008
Total Posts: 126
05 Mar 2012 01:16 PM
@xvgigakid

All I was able to match that to is the, "Local Gui".

enabled = true
function onButton1Down(mouse)
if not enabled then
return
end

enabled = false
mouse.Icon = "rbxasset://textures\\GunWaitCursor.png"

wait(.5)
mouse.Icon = "rbxasset://textures\\GunCursor.png"
enabled = true

end

function onEquippedLocal(mouse)

if mouse == nil then
print("Mouse not found")
return
end

mouse.Icon = "rbxasset://textures\\GunCursor.png"
mouse.Button1Down:connect(function() onButton1Down(mouse) end)
end


Tool.Equipped:connect(onEquippedLocal)


Which part did you mean?
mouse.Button1Down:connect(function() onButton1Down(mouse) ?
Report Abuse
Rangerko is not online. Rangerko
Joined: 12 Sep 2008
Total Posts: 126
05 Mar 2012 01:22 PM
Does anyone know where I should insert the code he posted?
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
05 Mar 2012 01:29 PM
Get rid of the LocalGui script. Look in your LinkedSword script, for a Tool.Activated:connect line. Replace that line with xgiga's code.
Report Abuse
Rangerko is not online. Rangerko
Joined: 12 Sep 2008
Total Posts: 126
05 Mar 2012 01:44 PM
@AgentFirefox

I deleted the LocalGui script, and modifyed a line of the code to what he said.

I changed...

script.Parent.Activated:connect(onActivated)
script.Parent.Equipped:connect(onEquipped)
to
while true do
wait(3)
SwingSword()
end
script.Parent.Equipped:connect(onEquipped)

That doesn't seem to work.
There is nothing showing up in the output, but a script is added in the LinkedSword model called "toolanim". The value of toolanim seems to be randomized with both Slash and Lunge.

The humanoid contains these scripts...

Animate
Health
Humanoid
LinkedSword
Mode
Regenerate
SwordCarrier
Head
Left Arm
Left Leg
Right Arm
Right Leg
Torso

My place has the updated script inside of the LinkedSword, I went inside and it didn't work.
Report Abuse
Rangerko is not online. Rangerko
Joined: 12 Sep 2008
Total Posts: 126
05 Mar 2012 02:02 PM
Anyone know what is wrong?
Report Abuse
top1 is not online. top1
Joined: 05 Mar 2009
Total Posts: 115
05 Mar 2012 02:08 PM
..you should've re-named swingsword with the swing function..
Report Abuse
Rangerko is not online. Rangerko
Joined: 12 Sep 2008
Total Posts: 126
05 Mar 2012 02:19 PM
This is what I have so far... All this does is make the LinkedSword tool inside the humanoid create a "toolanim". Still nothing in the output box.x


%B7Yc4g3cVF2vsIKTu48R1nScXPd5Vo60+xN0Q76AakHULM5fe1mr5zRUX5JSWoGHEo1edTgpe64xv21qdoLhD/SPEfbcHqsq1yly+4qaywNLH/YfQ7Hg7BosLHdrvJ45miA7slD6WHxMwAIne/oTw6Xs2G7dH4j1MSnDIsxiy8I=%%1014475%-------- OMG HAX

r = game:service("RunService")


local damage = 5


local slash_damage = 10
local lunge_damage = 30

sword = script.Parent.Handle
Tool = script.Parent


local SlashSound = Instance.new("Sound")
SlashSound.SoundId = "rbxasset://sounds\\swordslash.wav"
SlashSound.Parent = sword
SlashSound.Volume = .7

local LungeSound = Instance.new("Sound")
LungeSound.SoundId = "rbxasset://sounds\\swordlunge.wav"
LungeSound.Parent = sword
LungeSound.Volume = .6

local UnsheathSound = Instance.new("Sound")
UnsheathSound.SoundId = "rbxasset://sounds\\unsheath.wav"
UnsheathSound.Parent = sword
UnsheathSound.Volume = 1


function blow(hit)
if (hit.Parent == nil) then return end -- happens when bullet hits sword

local humanoid = hit.Parent:findFirstChild("Humanoid")
local vCharacter = Tool.Parent
local vPlayer = game.Players:playerFromCharacter(vCharacter)
local hum = vCharacter:findFirstChild("Humanoid") -- non-nil if tool held by a character
if humanoid~=nil and humanoid ~= hum and hum ~= nil then
-- final check, make sure sword is in-hand

local right_arm = vCharacter:FindFirstChild("Right Arm")
if (right_arm ~= nil) then
local joint = right_arm:FindFirstChild("RightGrip")
if (joint ~= nil and (joint.Part0 == sword or joint.Part1 == sword)) then
tagHumanoid(humanoid, vPlayer)
humanoid:TakeDamage(damage)
wait(1)
untagHumanoid(humanoid)
end
end


end
end


function tagHumanoid(humanoid, player)
local creator_tag = Instance.new("ObjectValue")
creator_tag.Value = player
creator_tag.Name = "creator"
creator_tag.Parent = humanoid
end

function untagHumanoid(humanoid)
if humanoid ~= nil then
local tag = humanoid:findFirstChild("creator")
if tag ~= nil then
tag.Parent = nil
end
end
end


function attack()
damage = slash_damage
SlashSound:play()
local anim = Instance.new("StringValue")
anim.Name = "toolanim"
anim.Value = "Slash"
anim.Parent = Tool
end

function lunge()
damage = lunge_damage

LungeSound:play()

local anim = Instance.new("StringValue")
anim.Name = "toolanim"
anim.Value = "Lunge"
anim.Parent = Tool


force = Instance.new("BodyVelocity")
force.velocity = Vector3.new(0,10,0) --Tool.Parent.Torso.CFrame.lookVector * 80
force.Parent = Tool.Parent.Torso
wait(.25)
swordOut()
wait(.25)
force.Parent = nil
wait(.5)
swordUp()

damage = slash_damage
end

function swordUp()
Tool.GripForward = Vector3.new(-1,0,0)
Tool.GripRight = Vector3.new(0,1,0)
Tool.GripUp = Vector3.new(0,0,1)
end

function swordOut()
Tool.GripForward = Vector3.new(0,0,1)
Tool.GripRight = Vector3.new(0,-1,0)
Tool.GripUp = Vector3.new(-1,0,0)
end

function swordAcross()
-- parry
end


Tool.Enabled = true
local last_attack = 0
function onActivated()

if not Tool.Enabled then
return
end

Tool.Enabled = false

local character = Tool.Parent;
local humanoid = character.Humanoid
if humanoid == nil then
print("Humanoid not found")
return
end

t = r.Stepped:wait()

if (t - last_attack < .2) then
lunge()
else
attack()
end

last_attack = t

--wait(.5)

Tool.Enabled = true
end


function onEquipped()
UnsheathSound:play()
end


while true do
wait(3)
onActivated()
end
script.Parent.Equipped:connect(onEquipped)


connection = sword.Touched:connect(blow)


Report Abuse
Rangerko is not online. Rangerko
Joined: 12 Sep 2008
Total Posts: 126
05 Mar 2012 02:42 PM
Everyone keeps going offline whenever they reply...
Report Abuse
top1 is not online. top1
Joined: 05 Mar 2009
Total Posts: 115
05 Mar 2012 02:54 PM
Remove the stuff before omg hax comment
Report Abuse
Rangerko is not online. Rangerko
Joined: 12 Sep 2008
Total Posts: 126
05 Mar 2012 03:04 PM
@Top1
I got feedback from the output when I did that!

16:03:28 - Workspace.Humanoid.LinkedSword.SwordScript:165: attempt to call global 'SwingSword' (a nil value)
16:03:28 - Script "Workspace.Humanoid.LinkedSword.SwordScript", Line 165
16:03:28 - stack end
Report Abuse
top1 is not online. top1
Joined: 05 Mar 2009
Total Posts: 115
05 Mar 2012 03:09 PM
I told you to change it to the real swing function name..
Report Abuse
Rangerko is not online. Rangerko
Joined: 12 Sep 2008
Total Posts: 126
05 Mar 2012 03:16 PM
Oh sorry, point taken.
Which function from the script do you think is the swingsword function?
Report Abuse
Rangerko is not online. Rangerko
Joined: 12 Sep 2008
Total Posts: 126
05 Mar 2012 05:24 PM
Does anyone know?
Report Abuse
Rangerko is not online. Rangerko
Joined: 12 Sep 2008
Total Posts: 126
05 Mar 2012 06:37 PM
When I used the Lunge() function, they humanoid would simulate jumping and lunging the sword forward. The jump was probably the lunge properties.

I want the humanoid to slash, not lunge. Anyone know how to fix that?
Report Abuse
luminesc is not online. luminesc
Joined: 21 Feb 2012
Total Posts: 61
05 Mar 2012 06:45 PM
Use the SLash() function...
Report Abuse
Rangerko is not online. Rangerko
Joined: 12 Sep 2008
Total Posts: 126
05 Mar 2012 06:54 PM
@luminesc
There is no slash function and I do not know how to modify it to make it that.

Also, there is A LOT of "toolanim" being made inside the bots LinkedSword... How can I have these auto delete?
Report Abuse
luminesc is not online. luminesc
Joined: 21 Feb 2012
Total Posts: 61
05 Mar 2012 07:24 PM
The slash is the same thing as lunge but different animation.
Report Abuse
Rangerko is not online. Rangerko
Joined: 12 Sep 2008
Total Posts: 126
06 Mar 2012 07:42 AM
Sorry, I don't think I typed that clearly.
There is no slash function inside the sword script.
I changed

lunge()

to

slash()

and got

08:37:17 - Workspace.Humanoid.LinkedSword.SwordScript:165: attempt to call global 'slash' (a nil value)
08:37:17 - Script "Workspace.Humanoid.LinkedSword.SwordScript", Line 165
08:37:17 - stack end

I need someone to help me make a slash() function.
Report Abuse
Rangerko is not online. Rangerko
Joined: 12 Sep 2008
Total Posts: 126
06 Mar 2012 08:32 AM
Nobody knows how I can add a slash function to the script posted above?
I am so close to finishing this humanoid, all I need is for him to slash...
Report Abuse
tehepicford is not online. tehepicford
Joined: 26 Aug 2011
Total Posts: 1486
06 Mar 2012 08:32 AM
Help my post!

http://www.roblox.com/Forum/ShowPost.aspx?PostID=63914144
Report Abuse
Rangerko is not online. Rangerko
Joined: 12 Sep 2008
Total Posts: 126
06 Mar 2012 08:35 AM
Sorry, I'm not as much as an expert as most people here.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image