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
We use cookies to offer you a better experience. By using Roblox.com, you are agreeing to our Privacy and Cookie Policy.
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Script Help

Previous Thread :: Next Thread 
Rapster2 is not online. Rapster2
Joined: 16 Oct 2009
Total Posts: 1865
18 Dec 2013 07:53 PM
Here is my code for a game I am working on to practice my scripting skills.

model = Instance.new("Model",workspace)
Model = Workspace.model
debounce = true

function ballMaker()
local num = math.random(50,100)
ball = Instance.new("Part",model)
ball.Size = Vector3.new(num,num,num)
ball.Anchored = false
ball.Position = Vector3.new(math.random(-250,250),250,10)
ball.FormFactor = "Custom"
ball.Shape = 'Ball'
ball.BrickColor = BrickColor.new(255,255,255)
ball.Material = "Concrete"
ball.BottomSurface = "Smooth"
ball.TopSurface = "Smooth"
end

function ballGenerator()
while debounce do
ballMaker()
wait(0.5)
end
end

ballGenerator()

function onTouch(hit)
pcall (function()
hit.ball.Humanoid:TakeDamage(100)
Player.TeamColor = "Really Red"
end)
end

for i,v in pairs(Workspace.model:GetChildren()) do
if v:IsA("Part") then
v.Touched:connect(function(hit)onTouch(hit) end)
end
end

function gameWin()
if game.Workspace:GetChildren("model") then
for i,v in pairs (Model:GetChildren()) do
if v:IsA("Part") then
v:Destroy()
end
end
end
players = Players:GetChildren()
players.Humanoid.WalkSpeed = 0
winner = Teams.Winner:FindFirstChild("Player")
debounce = false
message1 = Instance.new("Message",workspace)
message1.Text = winner.Name + " " + "is the winner! Congratulations!"
wait(5)
message1:Destroy()
wait(5)
message2 = Instance.new("Message",workspace)
message2.Text = "Setting up for next round..."
wait(5)
message2:Destroy()
for i,x in pairs (Players:GetChildren()) do
x.Humanoid:TakeDamage(100)
x.TeamColor = "Institutional white"
end
end

game.Workspace.WinnerSpawn.Touched:connect(gameWin)

I have two main problems:

1. My snowballs (the part created in ballMaker()) do not kill when a player touches them
2. When a player touches the WinnerSpawn (a SpawnPoint), gameWin does not run.

I've tried everything, any tips/help? Thanks!
Report Abuse
FreeScriptMaker is not online. FreeScriptMaker
Joined: 29 Nov 2013
Total Posts: 2275
18 Dec 2013 07:55 PM
tl;dr
Report Abuse
awesome404 is not online. awesome404
Joined: 11 Jan 2009
Total Posts: 3601
18 Dec 2013 07:58 PM
tl;dr
Report Abuse
DrWaffler is not online. DrWaffler
Joined: 16 Sep 2011
Total Posts: 4248
18 Dec 2013 08:01 PM
That was a tl;dr but I think I found this from my glance.

if game.Workspace:GetChildren("model") then


You never named the model, I do not think.

--[Territory Conquest Developer, Valerian Studios Developer, Business Casual Narwhal Moai. ]]--
Report Abuse
Rapster2 is not online. Rapster2
Joined: 16 Oct 2009
Total Posts: 1865
18 Dec 2013 08:10 PM
Sorry for the long post...

My main concern right now is getting the gameWin() function to run when I touch the SpawnPoint.
Report Abuse
lolb3 is not online. lolb3
Joined: 16 Jan 2010
Total Posts: 2268
18 Dec 2013 08:14 PM
if game.Workspace:GetChildren("model") then

what i don't even

if game.Workspace.Model:GetChildren() then
Report Abuse
Rapster2 is not online. Rapster2
Joined: 16 Oct 2009
Total Posts: 1865
18 Dec 2013 08:21 PM
*facepalm* Forgot to fix that part. Thanks for pointing that out to me lolb. My question is, why doesn't this call the gameWin() function when the WinnerSpawn spawnpoint is touched?

game.Workspace.WinnerSpawn.Touched:connect(gameWin)
Report Abuse
lolb3 is not online. lolb3
Joined: 16 Jan 2010
Total Posts: 2268
18 Dec 2013 08:23 PM
I'm not entirely sure i'll get back to you on that
Report Abuse
lolb3 is not online. lolb3
Joined: 16 Jan 2010
Total Posts: 2268
18 Dec 2013 08:26 PM
model = Instance.new("Model",workspace)
Model = Workspace.model

well there's our problem

Just define Model once with

model = Instance.new("Model", workspace)

First problem with the original code
When you're grabbing something called "model/Model" out of the workspace, there may be other objects named model

second problem

You just defined model and Model, and grabbed Model with the wrong caps
oops
Report Abuse
lolb3 is not online. lolb3
Joined: 16 Jan 2010
Total Posts: 2268
18 Dec 2013 08:27 PM
Also this isn't C++ or Java. You join strings with code via .. not +


message1.Text = winner.Name .. " " .. "is the winner! Congratulations!"
Report Abuse
Rapster2 is not online. Rapster2
Joined: 16 Oct 2009
Total Posts: 1865
18 Dec 2013 08:37 PM
Ok, I fixed that, but it still doesn't work. I checked the wiki, and you can call a Touched event on a SpawnPoint, but for some reason it isn't working.
Report Abuse
Rapster2 is not online. Rapster2
Joined: 16 Oct 2009
Total Posts: 1865
18 Dec 2013 09:04 PM
bump
Report Abuse
ArbiterOfDeath is not online. ArbiterOfDeath
Joined: 20 Jun 2011
Total Posts: 1458
18 Dec 2013 09:13 PM
wtf?

v.Touched:connect(function(hit)onTouch(hit) end)

Use this:
v.Touched:connect(onTouch)

Could it be that the script never gets to that point in execution because it is stuck in this loop?

function ballGenerator()
while debounce do
ballMaker()
wait(0.5)
end
end

ballGenerator()

Try to print something out right before you set up the connection, so that you can tell if that code ever runs.
Report Abuse
Rapster2 is not online. Rapster2
Joined: 16 Oct 2009
Total Posts: 1865
18 Dec 2013 09:35 PM
Arbiter, you're a genius.

Turns out my script was indeed getting stuck in my ballGenerator while loop.

Now to see if the rest of my code works, and to figure out a way to keep spawning balls while not getting trapped in an endless loop.
Report Abuse
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
18 Dec 2013 10:24 PM
ball.BrickColor = BrickColor.new(255,255,255)

I'm surprised this worked...

shouldnt it be ball.BrickColor = BrickColor.new(Color3.new(255/255,255/255,255/255))?

Player.TeamColor = "Really Red"
Player isnt defined, nor is = "Really red"

BrickColor.new("Really red")

players = Players:GetChildren() Players isnt defined.

winner = Teams.Winner:FindFirstChild("Player") Teams isnt defined

hit.ball.Humanoid:TakeDamage(100) wat.
Report Abuse
awesome404 is not online. awesome404
Joined: 11 Jan 2009
Total Posts: 3601
20 Dec 2013 01:03 PM
Here's your problem: when a game checks a script when the game is launched, it stops the check mid-script when there's an error. So the:
Workspace:GetChildren("model")
is wrong. Thus the rest of the script is forgotten about until you fix that error
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