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

Re: need a better way of doing this

Previous Thread :: Next Thread 
badfitz67 is not online. badfitz67
Joined: 03 Jun 2010
Total Posts: 13165
13 Jan 2016 12:22 PM
I made a puzzle game shown here:
http://www.roblox.com/games/342564215/Puzzle


and I need a better way of getting the blocks around the clicked block

I came up with this:

local ab = v.Position + Vector3.new(2,0,0)
local be = v.Position - Vector3.new(2,0,0)
local le = v.Position - Vector3.new(0,0,2)
local ri = v.Position + Vector3.new(0,0,2)

for _, c in pairs(sp:GetChildren()) do
if c:IsA("Part") then
if c.Position == Vector3.new(math.floor(ab.X),ab.Y,math.floor(ab.Z)) then
ab = c.Name
elseif c.Position == Vector3.new(math.floor(be.X),be.Y,math.floor(be.Z)) then
be = c.Name
elseif c.Position == Vector3.new(math.floor(le.X),le.Y,math.floor(le.Z)) then
le = c.Name
elseif c.Position == Vector3.new(math.floor(ri.X),le.Y,math.floor(ri.Z)) then
le = c.Name
end
end
end

It works fine but sometimes the left block next to the clicked block wont turn green.

I've printed le and ri and I got this:
39, 4.14999962, 12.999999

I tried to use math.floor:
for _, c in pairs(sp:GetChildren()) do
if c:IsA("Part") then
if c.Position == Vector3.new(math.floor(ab.X),ab.Y,math.floor(ab.Z)) then
ab = c.Name
elseif c.Position == Vector3.new(math.floor(be.X),be.Y,math.floor(be.Z)) then
be = c.Name
elseif c.Position == Vector3.new(math.floor(le.X),le.Y,math.floor(le.Z)) then
le = c.Name
elseif c.Position == Vector3.new(math.floor(ri.X),ri.Y,math.floor(ri.Z)) then
ri = c.Name
end
end
end

but I get this error:

18:21:56.533 - Workspace.Model.Script:22: bad argument #1 to 'floor' (number expected, got nil)
18:21:56.533 - Script 'Workspace.Model.Script', Line 22
18:21:56.533 - Stack End


You're a blunt tool, old man.
Report Abuse
Orced is not online. Orced
Joined: 08 Apr 2010
Total Posts: 1301
13 Jan 2016 12:28 PM
Firstable, better use CFrame instead of Vector3. Vector3 sometimes messes things up and doesnt place the part where you want it to be. But the system is the same.
Secondable, math.floor(ab.CFrame.Z) --< or Vector3.Z, depends if you listen to me or not
Report Abuse
BothAngles is not online. BothAngles
Joined: 01 Dec 2011
Total Posts: 9604
13 Jan 2016 01:20 PM
1. You're replacing the variables with a string (don't know why it's saying nil though)
2. That's horribly inefficient
Report Abuse
badfitz67 is not online. badfitz67
Joined: 03 Jun 2010
Total Posts: 13165
13 Jan 2016 01:24 PM
"Inefficient"

hence this thread

You're a blunt tool, old man.
Report Abuse
BothAngles is not online. BothAngles
Joined: 01 Dec 2011
Total Posts: 9604
13 Jan 2016 01:30 PM
Workspace
-Parts (Model)
--1 (Model, yPos)
---1_1 (Part, xPos_zPos)
Report Abuse
badfitz67 is not online. badfitz67
Joined: 03 Jun 2010
Total Posts: 13165
13 Jan 2016 01:35 PM
changed back to an old way of doing it:

local ab = tostring(tonumber(v.Name)-4)
local be = tostring(tonumber(v.Name)+4)
local le = tostring(tonumber(v.Name)-1)
local ri = tostring(tonumber(v.Name)+1)
if v.Name == "5" or v.Name == "9" or v.Name == "13" then
print("HI!")
le = nil
elseif v.Name == "4" or v.Name == "8" or v.Name == "12" then
ri = nil
end


it works fine but I want to get rid of the if statement(if possible without changing what I'm doing to get the blocks around it), it's there to stop glitches like this:

https://twitter.com/DucktorCid/status/687356907284238337



You're a blunt tool, old man.
Report Abuse
badfitz67 is not online. badfitz67
Joined: 03 Jun 2010
Total Posts: 13165
13 Jan 2016 02:51 PM
b

You're a blunt tool, old man.
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