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 » Scripters
Home Search
 

Re: Scripters I need your help!

Previous Thread :: Next Thread 
aqw559 is not online. aqw559
Joined: 05 Feb 2012
Total Posts: 5
20 Nov 2017 12:37 PM
I recently wanted to learn lua and I'm getting into it, although im currently stuck.
I've made a classic cannon that fires upon a mouseclick.

I want the projectile to explode if it only hit a part with a certain name, I know it has to do something with:
PartName.Touched:connect()

Report Abuse
ClanNotGuilds is not online. ClanNotGuilds
Joined: 24 Dec 2008
Total Posts: 25571
20 Nov 2017 12:52 PM
You're right about a touched connect, however not exactly how you specified. Thing is with this, I'm going to leave it to you to figure out how to insert an explosion into the part as I want this to be somewhat of a lesson rather than just me handing you a complete script.

function ExplodeOnTouch(hit)
if hit.Name == "PartName" then -- This would be the partname
print("ka-boom") -- Currently prints "ka-boom" into console whenever script.Parent touches a part with 'PartName'.
end
end

script.Parent.Touched:connect(ExplodeOnTouch)
Report Abuse
Blockzez is not online. Blockzez
Joined: 11 Jun 2017
Total Posts: 15
20 Nov 2017 12:54 PM
Like this?
(Insert Part Object here).Touched:connect(function()
local Explosion = Instance.new("Explosion")
Explosion.Position = (Insert Part Object here).Position
Explosion.Parent = (Insert Part Object here)
end)
Report Abuse
Bonys02 is not online. Bonys02
Joined: 05 Dec 2009
Total Posts: 37
20 Nov 2017 01:17 PM
Touched event function need the touched part as parameter
Part.Touched:connect(function(hit)
end)
Report Abuse
aqw559 is not online. aqw559
Joined: 05 Feb 2012
Total Posts: 5
20 Nov 2017 01:22 PM
function ExplodeOnTouch(hit)
if hit then
local Explosion = Instance.new("Explosion")
Explosion.Parent = game.Workspace
Explosion.Position = Ball.Position
wait(1)
Ball:Destroy()
end
end

Wall.Touched:connect(ExplodeOnTouch)

I assume? Yet nothing happens.
Report Abuse
ClanNotGuilds is not online. ClanNotGuilds
Joined: 24 Dec 2008
Total Posts: 25571
20 Nov 2017 01:49 PM
You're better off making the parent the Ball, not workspace.
Report Abuse
aqw559 is not online. aqw559
Joined: 05 Feb 2012
Total Posts: 5
20 Nov 2017 01:59 PM
--//Cannon Ball
local Wall = game.Workspace.WallModel.Wall
local Ball = game.ServerStorage.CannonBall

function ExplodeOnTouch(hit)
if hit then
local Explosion = Instance.new("Explosion")
Explosion.Parent = Ball.Parent
Explosion.Position = Ball.Position
wait(1)
Ball:Destroy()
end
end

Wall.Touched:connect(ExplodeOnTouch)

This is the whole script the cannonball is using, I tried changing the parent from workspace to the ball if that's what you meant.
Still didn't work.
Report Abuse
ClanNotGuilds is not online. ClanNotGuilds
Joined: 24 Dec 2008
Total Posts: 25571
20 Nov 2017 02:16 PM
function ExplodeOnTouch(hit)
if hit.Name == "CannonBall" then
print("ka-boom")
end
end

script.Parent.Touched:connect(ExplodeOnTouch)

Put this into your wall, test to see if the console prints "ka-boom" first.
Report Abuse
Blockzez is not online. Blockzez
Joined: 11 Jun 2017
Total Posts: 15
20 Nov 2017 02:18 PM
(Update to my post)
Fixed:
(Insert Part Object here).Touched:connect(function(hit)
if hit ~= game.Players.LocalPlayers.Character.Humanoid then
return
end
local Explosion = Instance.new("Explosion")
Explosion.Position = (Insert Part Object here).Position
Explosion.Parent = (Insert Part Object here)
end)
Report Abuse
aqw559 is not online. aqw559
Joined: 05 Feb 2012
Total Posts: 5
20 Nov 2017 02:37 PM
I did what you told me and it did not work, I can provide you with the Cannons script too.

--//Cannon
local Barrel = game.Workspace.Cannon.Barrel
local Button = game.Workspace.Cannon.Button
local Ball = game.ServerStorage.CannonBall
local BallCopy = Ball:Clone()

Button.ClickDetector.MouseClick:connect(function()
if Button then
BallCopy.Parent = game.Workspace
BallCopy.Position = Barrel.Position
BallCopy.Velocity = Vector3.new(110,0,0)


end
end)
Report Abuse
ClanNotGuilds is not online. ClanNotGuilds
Joined: 24 Dec 2008
Total Posts: 25571
20 Nov 2017 02:49 PM
The console doesn't print kaboom? That's strange because I have a part called Wall which contains the script and I am dropping a part called CannonBall on it now and its printing ka-boom.
Report Abuse
aqw559 is not online. aqw559
Joined: 05 Feb 2012
Total Posts: 5
20 Nov 2017 03:29 PM
I got it working now, thanks for putting down your time to help me.
Report Abuse
ClanNotGuilds is not online. ClanNotGuilds
Joined: 24 Dec 2008
Total Posts: 25571
20 Nov 2017 03:39 PM
Glad to hear.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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