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: Ultimate Confusion

Previous Thread :: Next Thread 
thek00lkid is not online. thek00lkid
Joined: 18 Jun 2011
Total Posts: 2778
09 Feb 2012 07:35 AM
Here's my script.


local Tool = script.Parent;
local User
local walking = 0
local hold
local walk
local gunning = script.Parent:FindFirstChild("GunMode").Value
enabled = true
function onButton1Down(mouse)
if not enabled then
return
end
if gunning == false then
local vCharacter = Tool.Parent
local hum = vCharacter:findFirstChild("Humanoid")
blah = hum:LoadAnimation(script.Parent.Slash)
blah:Play()

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

wait(1.6)
mouse.Icon = "rbxasset://textures\\GunCursor.png"
enabled = true
if gunning == true then
User = Tool.Parent --Set the User variable to the character of the person using the tool.
local Ray = Ray.new(Tool.Handle.CFrame.p,(mouse.Hit.p-Tool.Handle.CFrame.p).unit*300) --Make a the ray.
local Hit,Position = game.Workspace:FindPartOnRay(Ray,User) --Check for collisions along the ray.
if Hit then --If it hits something.
if Hit.Parent:FindFirstChild("Humanoid") then --If the thing the ray hit has a humanoid.
Hit.Parent.Humanoid:TakeDamage(30) --Do 30 damage if they don't have a forcefield.
end --End the humanoid check.
end --End the hit check.
local RayPart = Instance.new("Part",User) --Create a part in the user.
RayPart.Name = "RayPart" --Set its name.
RayPart.BrickColor = BrickColor.new("Bright orange") --Set its color.
RayPart.Transparency = 0.5 --Set its transparency.
RayPart.Anchored = true --Set whether it will fall or not.
RayPart.CanCollide = false --Set whether people can walk though it or not.
RayPart.TopSurface = Enum.SurfaceType.Smooth --Make it smooth on the top.
RayPart.BottomSurface = Enum.SurfaceType.Smooth --Make it smooth on the bottom.
RayPart.formFactor = Enum.FormFactor.Custom --Make it so it can be small.
local Distance = (Position-Tool.Handle.CFrame.p).magnitude --Find the distance between the click and the gun.
RayPart.Size = Vector3.new(0.2,0.2,Distance) --Set its size to the distance.
RayPart.CFrame = CFrame.new(Position,Tool.Handle.CFrame.p) * CFrame.new(0,0,-Distance/2) --Move it halfway.
game.Debris:AddItem(RayPart,0.1) --Add it to the debris.
end
end
end

function onKeyDown(key)
key:lower()
if key == "f" and gunning == false then
script.Parent.GripForward = Vector3.new(-1,0,5)
script.Parent:FindFirstChild("GunMode").Value = true
gunning = true
return end
if key == "f" and gunning == true then
script.Parent.GripForward = Vector3.new(-1,0,0)
script.Parent:FindFirstChild("GunMode").Value = false
gunning = false
return end
if walk and (key == "w") or (key == "a") or (key == "s") or (key == "d") then
walk:Play()
walking = walking + 1
end
end

function onKeyUp(key)
if walk and (key == "w") or (key == "a") or (key == "s") or (key == "d") then
walking = walking - 1
if walking == 0 then
walk:Stop(0)
end
end
end

function onEquippedLocal(mouse)

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

local vCharacter = Tool.Parent
local humanoid = vCharacter.Humanoid

hold = humanoid:LoadAnimation(Tool.holdstaff)
walk = humanoid:LoadAnimation(Tool.walkstaff)

hold:Play()

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

function onUnequippedLocal()
hold:Stop()
walk:Stop()

hold = nil
walk = nil
end

Tool.Equipped:connect(onEquippedLocal)
Tool.Unequipped:connect(onUnequippedLocal)


Now pretend most of it doesn't exist, except the function MouseButton1Down. This is the LocalGui. Here's the problem: I'm trying to make a sword that has two modes, one is as a sword, and in the other mode it shoots lazers!!! Yes, it's ridiculous, but bear with me. Here's my lazer script. I got it off the wiki because I know NOTHING about how to raycast and how to create guns.

local Tool = script.Parent --Set a variable for the tool.
local User --Create a nil value for the character which we can't find yet.
Tool.Equipped:connect(function(mouse) --When it's equipped fire a function.
User = Tool.Parent --Set the User variable to the character of the person using the tool.
mouse.Button1Down:connect(function() --When the left mouse button is clicked fire a function.
local Ray = Ray.new(Tool.Handle.CFrame.p,(mouse.Hit.p-Tool.Handle.CFrame.p).unit*300) --Make a the ray.
local Hit,Position = game.Workspace:FindPartOnRay(Ray,User) --Check for collisions along the ray.
if Hit then --If it hits something.
if Hit.Parent:FindFirstChild("Humanoid") then --If the thing the ray hit has a humanoid.
Hit.Parent.Humanoid:TakeDamage(30) --Do 30 damage if they don't have a forcefield.
end --End the humanoid check.
end --End the hit check.
local RayPart = Instance.new("Part",User) --Create a part in the user.
RayPart.Name = "RayPart" --Set its name.
RayPart.BrickColor = BrickColor.new("Bright red") --Set its color.
RayPart.Transparency = 0.5 --Set its transparency.
RayPart.Anchored = true --Set whether it will fall or not.
RayPart.CanCollide = false --Set whether people can walk though it or not.
RayPart.TopSurface = Enum.SurfaceType.Smooth --Make it smooth on the top.
RayPart.BottomSurface = Enum.SurfaceType.Smooth --Make it smooth on the bottom.
RayPart.formFactor = Enum.FormFactor.Custom --Make it so it can be small.
local Distance = (Position-Tool.Handle.CFrame.p).magnitude --Find the distance between the click and the gun.
RayPart.Size = Vector3.new(0.2,0.2,Distance) --Set its size to the distance.
RayPart.CFrame = CFrame.new(Position,Tool.Handle.CFrame.p) * CFrame.new(0,0,-Distance/2) --Move it halfway.
game.Debris:AddItem(RayPart,0.1) --Add it to the debris.
end)
end)


Now please tell me what to facepalm at ;)

Report Abuse
Trioxide is not online. Trioxide
Joined: 29 Mar 2011
Total Posts: 32902
09 Feb 2012 07:56 AM
[ Content Deleted ]
Report Abuse
noobkid is not online. noobkid
Joined: 17 Sep 2007
Total Posts: 649
09 Feb 2012 08:02 AM
^

At last I had the opportunity use that mark.
Report Abuse
3lex33 is not online. 3lex33
Joined: 08 Oct 2008
Total Posts: 5220
09 Feb 2012 09:18 AM
You did remove second onEquipped function, did not you?
Report Abuse
thek00lkid is not online. thek00lkid
Joined: 18 Jun 2011
Total Posts: 2778
09 Feb 2012 10:52 AM
Yes, I removed the functions from the script so that It would work.
Report Abuse
thek00lkid is not online. thek00lkid
Joined: 18 Jun 2011
Total Posts: 2778
09 Feb 2012 06:22 PM
I know the lazer gun script works. It's broken on the MouseButton1Down function when I try to apply it.
Report Abuse
CrazyBananaMonkey is not online. CrazyBananaMonkey
Joined: 10 Nov 2009
Total Posts: 1599
09 Feb 2012 07:54 PM
Read the stickies, please: http://www.roblox.com/Forum/ShowPost.aspx?PostID=9772680; Don't post a large mess of code, and don't say 'Here. Fix my code.' Give us the output!
Report Abuse
thek00lkid is not online. thek00lkid
Joined: 18 Jun 2011
Total Posts: 2778
09 Feb 2012 09:54 PM
Need me to be more specefic and not explain the big picture?

Here:

function onButton1Down(mouse)
if not enabled then
return
end
if gunning == false then
local vCharacter = Tool.Parent
local hum = vCharacter:findFirstChild("Humanoid")
blah = hum:LoadAnimation(script.Parent.Slash)
blah:Play()

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

wait(1.6)
mouse.Icon = "rbxasset://textures\\GunCursor.png"
enabled = true
if gunning == true then
User = Tool.Parent --Set the User variable to the character of the person using the tool.
local Ray = Ray.new(Tool.Handle.CFrame.p,(mouse.Hit.p-Tool.Handle.CFrame.p).unit*300) --Make a the ray.
local Hit,Position = game.Workspace:FindPartOnRay(Ray,User) --Check for collisions along the ray.
if Hit then --If it hits something.
if Hit.Parent:FindFirstChild("Humanoid") then --If the thing the ray hit has a humanoid.
Hit.Parent.Humanoid:TakeDamage(30) --Do 30 damage if they don't have a forcefield.
end --End the humanoid check.
end --End the hit check.
local RayPart = Instance.new("Part",User) --Create a part in the user.
RayPart.Name = "RayPart" --Set its name.
RayPart.BrickColor = BrickColor.new("Bright orange") --Set its color.
RayPart.Transparency = 0.5 --Set its transparency.
RayPart.Anchored = true --Set whether it will fall or not.
RayPart.CanCollide = false --Set whether people can walk though it or not.
RayPart.TopSurface = Enum.SurfaceType.Smooth --Make it smooth on the top.
RayPart.BottomSurface = Enum.SurfaceType.Smooth --Make it smooth on the bottom.
RayPart.formFactor = Enum.FormFactor.Custom --Make it so it can be small.
local Distance = (Position-Tool.Handle.CFrame.p).magnitude --Find the distance between the click and the gun.
RayPart.Size = Vector3.new(0.2,0.2,Distance) --Set its size to the distance.
RayPart.CFrame = CFrame.new(Position,Tool.Handle.CFrame.p) * CFrame.new(0,0,-Distance/2) --Move it halfway.
game.Debris:AddItem(RayPart,0.1) --Add it to the debris.
end
end
end
Report Abuse
thek00lkid is not online. thek00lkid
Joined: 18 Jun 2011
Total Posts: 2778
09 Feb 2012 10:00 PM
There's no output.

HERE is the code for my lazers, it's from the wiki so it's. As you see the gun has two modes and that's why I have the check. Please tell me any logic errors or explain some things in this script. I didn't make the comments.


local Tool = script.Parent --Set a variable for the tool.
local User --Create a nil value for the character which we can't find yet.
Tool.Equipped:connect(function(mouse) --When it's equipped fire a function.
User = Tool.Parent --Set the User variable to the character of the person using the tool.
mouse.Button1Down:connect(function() --When the left mouse button is clicked fire a function.
local Ray = Ray.new(Tool.Handle.CFrame.p,(mouse.Hit.p-Tool.Handle.CFrame.p).unit*300) --Make a the ray.
local Hit,Position = game.Workspace:FindPartOnRay(Ray,User) --Check for collisions along the ray.
if Hit then --If it hits something.
if Hit.Parent:FindFirstChild("Humanoid") then --If the thing the ray hit has a humanoid.
Hit.Parent.Humanoid:TakeDamage(30) --Do 30 damage if they don't have a forcefield.
end --End the humanoid check.
end --End the hit check.
local RayPart = Instance.new("Part",User) --Create a part in the user.
RayPart.Name = "RayPart" --Set its name.
RayPart.BrickColor = BrickColor.new("Bright red") --Set its color.
RayPart.Transparency = 0.5 --Set its transparency.
RayPart.Anchored = true --Set whether it will fall or not.
RayPart.CanCollide = false --Set whether people can walk though it or not.
RayPart.TopSurface = Enum.SurfaceType.Smooth --Make it smooth on the top.
RayPart.BottomSurface = Enum.SurfaceType.Smooth --Make it smooth on the bottom.
RayPart.formFactor = Enum.FormFactor.Custom --Make it so it can be small.
local Distance = (Position-Tool.Handle.CFrame.p).magnitude --Find the distance between the click and the gun.
RayPart.Size = Vector3.new(0.2,0.2,Distance) --Set its size to the distance.
RayPart.CFrame = CFrame.new(Position,Tool.Handle.CFrame.p) * CFrame.new(0,0,-Distance/2) --Move it halfway.
game.Debris:AddItem(RayPart,0.1) --Add it to the debris.
end)
end)
Report Abuse
3lex33 is not online. 3lex33
Joined: 08 Oct 2008
Total Posts: 5220
09 Feb 2012 10:38 PM
Can you post the full code please? And, put a single print in onMouseButton1 function, just to see if engine responds to event or not, say the results please.
Report Abuse
thek00lkid is not online. thek00lkid
Joined: 18 Jun 2011
Total Posts: 2778
10 Feb 2012 09:10 AM
Nevermind, fixed it, I was missing an end on an if statement. Here it is.


local Tool = script.Parent;
local User
local walking = 0
local hold
local walk
local gunning = script.Parent:FindFirstChild("GunMode").Value
enabled = true
function onButton1Down(mouse)
if not enabled then
return
end
if gunning == false then
local vCharacter = Tool.Parent
local hum = vCharacter:findFirstChild("Humanoid")
blah = hum:LoadAnimation(script.Parent.Slash)
blah:Play()

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

wait(1.6)
mouse.Icon = "rbxasset://textures\\GunCursor.png"
enabled = true
end
if gunning == true then
print("This is mind boggling")
User = Tool.Parent --Set the User variable to the character of the person using the tool.
local Ray = Ray.new(Tool.Handle.CFrame.p,(mouse.Hit.p-Tool.Handle.CFrame.p).unit*300) --Make a the ray.
local Hit,Position = game.Workspace:FindPartOnRay(Ray,User) --Check for collisions along the ray.
if Hit then --If it hits something.
if Hit.Parent:FindFirstChild("Humanoid") then --If the thing the ray hit has a humanoid.
Hit.Parent.Humanoid:TakeDamage(30) --Do 30 damage if they don't have a forcefield.
end --End the humanoid check.
end --End the hit check.
local RayPart = Instance.new("Part",User) --Create a part in the user.
RayPart.Name = "RayPart" --Set its name.
RayPart.BrickColor = BrickColor.new("Bright orange") --Set its color.
RayPart.Transparency = 0.5 --Set its transparency.
RayPart.Anchored = true --Set whether it will fall or not.
RayPart.CanCollide = false --Set whether people can walk though it or not.
RayPart.TopSurface = Enum.SurfaceType.Smooth --Make it smooth on the top.
RayPart.BottomSurface = Enum.SurfaceType.Smooth --Make it smooth on the bottom.
RayPart.formFactor = Enum.FormFactor.Custom --Make it so it can be small.
local Distance = (Position-Tool.Handle.CFrame.p).magnitude --Find the distance between the click and the gun.
RayPart.Size = Vector3.new(0.2,0.2,Distance) --Set its size to the distance.
RayPart.CFrame = CFrame.new(Position,Tool.Handle.CFrame.p) * CFrame.new(0,0,-Distance/2) --Move it halfway.
game.Debris:AddItem(RayPart,0.1) --Add it to the debris.
end
end

function onKeyDown(key)
key:lower()
if key == "f" and gunning == false then
script.Parent.GripForward = Vector3.new(-1,0,5)
script.Parent:FindFirstChild("GunMode").Value = true
gunning = true
return end
if key == "f" and gunning == true then
script.Parent.GripForward = Vector3.new(-1,0,0)
script.Parent:FindFirstChild("GunMode").Value = false
gunning = false
return end
if walk and (key == "w") or (key == "a") or (key == "s") or (key == "d") then
walk:Play()
walking = walking + 1
end
end

function onKeyUp(key)
if walk and (key == "w") or (key == "a") or (key == "s") or (key == "d") then
walking = walking - 1
if walking == 0 then
walk:Stop(0)
end
end
end

function onEquippedLocal(mouse)

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

local vCharacter = Tool.Parent
local humanoid = vCharacter.Humanoid

hold = humanoid:LoadAnimation(Tool.holdstaff)
walk = humanoid:LoadAnimation(Tool.walkstaff)

hold:Play()

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

function onUnequippedLocal()
hold:Stop()
walk:Stop()

hold = nil
walk = nil
end

Tool.Equipped:connect(onEquippedLocal)
Tool.Unequipped:connect(onUnequippedLocal)
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