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: Why is this happening?

Previous Thread :: Next Thread 
Fedorakid is not online. Fedorakid
Joined: 17 Jul 2010
Total Posts: 7079
30 Apr 2013 02:50 PM
So i made a simple raycasting script and it works the first time, but when i die it doesen't do anything, why?
Report Abuse
Fedorakid is not online. Fedorakid
Joined: 17 Jul 2010
Total Posts: 7079
30 Apr 2013 02:51 PM
It shoots from my torso to where i click, oh and heres the script btw:

tool = script.Parent
me = game.Players.LocalPlayer.Character

tool.Selected:connect(function(mouse)
mouse.Button1Down:connect(function()

ray = Ray.new(me.Torso.CFrame.p, (mouse.Hit.p - me.Torso.CFrame.p ).unit*300)
ObjectRayHit,RayHitPosition = game.Workspace:FindPartOnRay(ray,me)

if ObjectRayHit and ObjectRayHit.Parent and ObjectRayHit:findFirstChild("Humanoid") then
ObjectRayHit.Humanoid:TakeDamage(25)
end

distance = (me.Torso.CFrame.p - RayHitPosition).magnitude
b = Instance.new("Part", me)
b.Name = "RayPart"
b.BrickColor = BrickColor.new("Bright red")
b.Anchored = true
b.CanCollide = false
b.TopSurface = "Smooth"
b.BottomSurface = "Smooth"
b.Size = Vector3.new(1, 1, distance)
b.CFrame = CFrame.new(RayHitPosition, me.Torso.CFrame.p) * CFrame.new(0,0,-distance/2)

game:GetService("Debris"):AddItem(b, 1)
end)
end)
Report Abuse
getkoed2 is not online. getkoed2
Joined: 11 Apr 2010
Total Posts: 1144
30 Apr 2013 03:24 PM
me = game.Players.LocalPlayer.Character

That's why it doesn't work if you reset.
I think this should work:

game.Players.LocalPlayer.CharacterAdded:wait()
me = game.Players.LocalPlayer.Character
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