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: sword script help

Previous Thread :: Next Thread 
rocko97 is not online. rocko97
Joined: 02 Jun 2009
Total Posts: 1157
11 Sep 2011 03:00 PM
The mathRandom part is broken i think because it picks one number and then always hits it. Instead of picking a different number each time.

dmg = math.random(10, 20)

hum = "Monster"

r = game:service("RunService")

ching = false

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

function blow(hit)
if ching == true then return end
local humanoid = hit.Parent:findFirstChild(hum)
local vCharacter = Tool.Parent
local vPlayer = game.Players:playerFromCharacter(vCharacter)
if humanoid~=nil then
tagHumanoid(humanoid, vPlayer)
local damage = dmg
humanoid:TakeDamage(damage)
local part = Instance.new("Part")
if (damage == 0) then
part.BrickColor = BrickColor.new(23)
else
part.BrickColor = BrickColor.new(21)
end
part.formFactor = 1
part.Shape = "Ball"
part.TopSurface = "0"
part.BottomSurface = "0"
part.Size = Vector3.new(1.375,1.375,1.375)
part.Position = hit.Parent.Head.Position+Vector3.new(math.random(-3.6,3.6),3.5,math.random(-3.6,3.6))
part.Anchored = true
local m = Instance.new("Model")
part.Parent = m
m.Parent = hit.Parent
m.Name = ""..damage.." Damage"
part.Name = "Head"
local h = Instance.new("Humanoid")
h.Parent = m
local body = Instance.new("BodyPosition")
body.position = Vector3.new(0,7.85,0)
body.Parent = part
part.CanCollide = false
part.Reflectance = 0.11
part.Transparency = 0.25
h.MaxHealth = 0
h.Health = 0
ching = true
wait(1)
ching = false
m:remove()
wait(.1)
untagHumanoid(humanoid)
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()

atk = {"Slash"; "Lunge"; "Slash"}
wew = atk[math.random(1, #atk)]

if (wew == "Slash") then
local anim = Instance.new("StringValue")
anim.Name = "toolanim"
anim.Value = "Slash"
anim.Parent = Tool
else
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)
force.Parent = Tool.Parent.Torso
wait(.25)
swordOut()
wait(.25)
force.Parent = nil
wait(.5)

swordUp()

end 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()
end


Tool.Enabled = true

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

attack()

wait(1)

Tool.Enabled = true
end


function onEquipped()

end


script.Parent.Activated:connect(onActivated)
script.Parent.Equipped:connect(onEquipped)


connection = sword.Touched:connect(blow)
Report Abuse
5943539 is not online. 5943539
Joined: 05 Jan 2010
Total Posts: 810
11 Sep 2011 03:08 PM
It's because you're calling the same number, instead of another number with math.random. Erase all references of dmg and put in math.random(10,20).

I don't believe in imaginary numbers.
Report Abuse
greatestdan is not online. greatestdan
Joined: 08 Sep 2008
Total Posts: 504
11 Sep 2011 03:18 PM
or you could move
dmg = math.random(10, 20) to nside the hit function. that would make it so every time someone is hit then a new numer is selected.
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