A Roblox Community

A community of Robloxians who want to learn to script and build on Roblox Studio.
 
HomeFAQRegisterLog in
If you're a experienced coder make some tutorials! It would really help the site grow.
Make sure you read the rules(Which can be found by clicking here)
If you're a beginner at coding, try some tutorials.
We have many Moderators/Admins watching this site. Contact them with Questions.
Let us know what your favorite sport is. By clicking here to vote (Click here)
This site is becoming inactive. Lets make it active.
Log in
Username:
Password:
Log in automatically: 
:: I forgot my password
Top posters
blueymaddog
 
naknak
 
Supernapalm
 
m27frogy
 
slayer9365
 
myrco919
 
branefreez
 
ninga95
 
CloneTrooper787
 
raboy117
 
Top posting users this month
Latest topics
» Send me an Email
January 8th 2016, 10:14 am by naknak

» [v1.6.0.0] Lua Script Obfuscator [No Bytecode]
July 6th 2015, 7:38 pm by m27frogy

» New Site Possibly
July 6th 2015, 4:16 pm by m27frogy

» Ambassador!
April 15th 2015, 11:40 pm by naknak

» Boop - Tag
April 13th 2015, 9:46 pm by naknak

» Vip Class Script
April 13th 2015, 4:54 pm by naknak

» Who's active?!
April 13th 2015, 4:52 pm by naknak

» Where to go from here.
April 13th 2015, 4:51 pm by naknak

» Genesis Point
July 17th 2014, 7:04 pm by branefreez

» Reward System
July 17th 2014, 5:41 am by m27frogy

» Script Request
July 10th 2014, 11:43 am by naknak

» local scripts?
July 10th 2014, 11:39 am by naknak

» Project: Reconstruction [Died]
July 10th 2014, 11:36 am by naknak

» Hi. I am new here
April 26th 2014, 4:01 pm by altshiftkey

» What's your favorite sport?
January 1st 2014, 2:13 pm by m27frogy

» FlashLight Script
January 1st 2014, 2:11 pm by m27frogy

» Gun Making! [READ DESC]
January 1st 2014, 2:10 pm by m27frogy

» Hi, I am new here!
November 26th 2013, 3:33 pm by Keanu73

» Improve Coding
October 26th 2013, 1:12 pm by pook03

» Simple Button
September 1st 2013, 6:19 pm by branefreez


Share | 
 

 Fun, fun....error -.-

View previous topic View next topic Go down 
AuthorMessage
Guest
Guest



PostSubject: Fun, fun....error -.-   August 2nd 2010, 10:58 pm

So, basically, the part doesn't go up and down the ramp correctly. It errors. Badly. I can't really explain it, but the problem is when the mode is 1. This is the script:

Code:
repeat
   wait()
until game.Workspace:findFirstChild(game.Players.LocalPlayer.Name .. "_Game")

local Down = false
local Origin = nil
local Y_POS = workspace.Base.Position.y + 0.4    -->   The position of the part on the Y-Axis
local Units = {}
local Selected = {}
local LookOut = {}

function Search(Place, Var)
   for Index, Value in pairs(Place) do
      if Var == 0 then
         if Value:IsA("BasePart") and Value.Transparency > 0.9 then
            table.insert(LookOut, Value)
         elseif Value.Name == "Game_Map" then
            Search(Value:GetChildren(), 0)
         end
      elseif Var == 1 then
         if Value.Name == "Units" then
            Search(Value:GetChildren(), 2)
         end
      elseif Var == 2 then
         table.insert(Units, Value)
      end
   end
end

Search(game.Workspace:GetChildren(), 0)
Search(game.Workspace:findFirstChild(game.Players.LocalPlayer.Name .. "_Game"):GetChildren(), 1)

local Mode = 0
local Part = Instance.new("Part")
Part.Anchored = true
Part.BottomSurface = Enum.SurfaceType.Smooth
Part.BrickColor = BrickColor.new("Bright green")
Part.CanCollide = false
Part.formFactor = Enum.FormFactor.Plate
Part.TopSurface = Enum.SurfaceType.Smooth
Part.Transparency = 0.3

coroutine.resume(
   coroutine.create(
      function()
         repeat
            wait()
         until game.Workspace:findFirstChild(game.Players.LocalPlayer.Name .. "_Game")
         local Model = game.Workspace:findFirstChild(game.Players.LocalPlayer.Name .. "_Game")
         Model.Units.DescendantAdded:connect(function(Obj)
            Units[table.maxn(Units)] = Obj
         end)

         Model.DescendantRemoving:connect(function(Obj)
            for Index, Value in pairs(Units) do
               if Value == Obj then
                  table.remove(Units, Index)
               end
            end
         end)
      end
   )
)

function IsInArea(Area, Checking)
   local Ranges = {
      ["X_Range"] = {
         Area.Position.x + Area.Size.x / 2,
         Area.Position.x + Area.Size.x / -2
      },
      ["Z_Range"] = {
         Area.Position.z + Area.Size.z / 2,
         Area.Position.z + Area.Size.z / -2
      }
   }
   local Sizes = {
      ["X_Size"] = {
         Checking.Position.x + Checking.Size.x / -2,
         Checking.Position.x + Checking.Size.x / 2
      },
      ["Z_Size"] = {
         Checking.Position.z + Checking.Size.z / -2,
         Checking.Position.z + Checking.Size.z / 2
      }
   }
   local True = {}
   if Ranges.X_Range[1] >= Sizes.X_Size[1] then
      table.insert(True, true)
      print(true)
   end
   if Ranges.X_Range[2] <= Sizes.X_Size[2] then
      table.insert(True, true)
      print(true)
   end
   if Ranges.Z_Range[1] >= Sizes.Z_Size[1] then
      table.insert(True, true)
      print(true)
   end
   if Ranges.Z_Range[2] <= Sizes.Z_Size[2] then
      table.insert(True, true)
      print(true)
   end
   if table.maxn(True) + 1 >= 4 then
      return true
   else
      return false
   end
end

script.Parent.Selected:connect(function(Mouse)
   Mouse.Button1Down:connect(function()
      repeat
         wait()
      until game.Workspace:findFirstChild(game.Players.LocalPlayer.Name .. "_Game")

      if Mode == 0 then
         if Mouse.Target ~= nil then
            Down = true
            Origin = Mouse.Hit.p
         end
      end
   end)

   Mouse.Move:connect(function()
      repeat
         wait()
      until game.Workspace:findFirstChild(game.Players.LocalPlayer.Name .. "_Game")

      if Mode == 0 then
         if Down == true and Mouse.Target ~= nil then
            local X = (Origin.x - Mouse.Hit.p.x)
            local Z = (Origin.z - Mouse.Hit.p.z)
            Part.Size = Vector3.new(math.abs(X), Y_POS, math.abs(Z))
            Part.CFrame = CFrame.new(Vector3.new(Origin:lerp(Mouse.Hit.p, 0.5).x, Y_POS, Origin:lerp(Mouse.Hit.p, 0.5).z))
            if Part.Parent == nil then
               Part.Parent = game.Workspace.CurrentCamera
            end
         end
      end
   end)

   Mouse.Button1Up:connect(function()
      repeat
         wait()
      until game.Workspace:findFirstChild(game.Players.LocalPlayer.Name .. "_Game")

      if Mode == 0 then
         Down = false
         for Index, Value in pairs(Units) do
            if IsInArea(Part, Value) then
               table.insert(Selected, Value)
            end
         end
         Part.Parent = nil
         Origin = nil
      elseif Mode == 1 and Mouse.Target ~= nil then
         for Index, Value in pairs(Selected) do
            delay(0, function()
               local Start = Value.CFrame.p
               local End = Mouse.Hit.p
               local Target
               local AtRamp = false
               local function Move(PreRun)

                  local function Path(Starting, Ending)
                     local lookVector = CFrame.new(Starting, Ending).lookVector
                     for Index = 0, (Ending - Starting).magnitude, 1 do
                        for _, Value in pairs(LookOut) do
                           if Value.CFrame:pointToObjectSpace(Starting:lerp(Ending, Index / (Target - Start).magnitude)).x > -(Value.Size.x / 2) and Value.CFrame:pointToObjectSpace(Starting:lerp(Ending, Index / (Target - Start).magnitude)).x < (Value.Size.x / 2) and Value.CFrame:pointToObjectSpace(Starting:lerp(Ending, Index / (Target - Start).magnitude)).y > -(Value.Size.y / 2) and Value.CFrame:pointToObjectSpace(Starting:lerp(Ending, Index / (Target - Start).magnitude)).y < (Value.Size.y / 2) and Value.CFrame:pointToObjectSpace(Starting:lerp(Ending, Index / (Target - Start).magnitude)).z > -(Value.Size.z / 2) and Value.CFrame:pointToObjectSpace(Starting:lerp(Ending, Index / (Target - Start).magnitude)).z < (Value.Size.z / 2) then
                              return false, game.Workspace.WorkAround.CFrame.p
                           end
                        end
                     end
                     return true, nil
                  end

                  if PreRun == false then
                     if End.y > Start.y then
                        if Value.CFrame.p.y < Start.y then
                           return
                        end
                        Target = game.Workspace.PreRamp.CFrame.p
--[[                        if Path(Start, End) == false then
                           local _, New = Path(Start, End)
                           Target = New
                        end
]]                     elseif End.y < Start.y then
                        if Value.CFrame.p.y < End.y then
                           return
                        end
                        Target = game.Workspace.PostRamp.CFrame.p
--[[                        if Path(Start, End) == false then
                           local _, New = Path(Start, End)
                           Target = New
                        end
]]                     else
                        Target = End
                     end
                  else
                     Start = Value.CFrame.p
                     if End.y > Start.y then
                        if Value.CFrame.p.y > Start.y + 0.5 and Value.CFrame.p.y < End.y - 0.5 then
                           Target = game.Workspace.PostRamp
                           return
                        elseif Value.CFrame.p.y > Start.y + 0.5 then
                           Target = End
                           return
                        end
                        Target = game.Workspace.PreRamp.CFrame.p
--[[                        if Path(Target, End) == false then
                           local _, New = Path(Target, End)
                           Target = New
                        end
]]                     elseif End.y < Start.y then
                        if Value.CFrame.p.y > Start.y + 0.5 and Value.CFrame.p.y < End.y - 0.5 then
                           Target = game.Workspace.PreRamp
                           return
                        elseif Value.CFrame.p.y < End.y - 0.5 then
                           Target = End
                           return
                        end
                        Target = game.Workspace.PostRamp.CFrame.p
--[[                        if Path(Target, End) == false then
                           local _, New = Path(Target, End)
                           Target = New
                        end
]]                     else
                        Target = End
                     end
                  end
                  for Index = 0, (Target - Start).magnitude, 1 do
                     Value.CFrame = CFrame.new(Start:lerp(Target, Index / (Target - Start).magnitude))
                     wait()
                  end
                  if Target ~= End then
                     Move(true)
                  end
               end
               Move(false)
            end)
         end
      end
   end)

   Mouse.KeyDown:connect(function(Key)
      repeat
         wait()
      until game.Workspace:findFirstChild(game.Players.LocalPlayer.Name .. "_Game")

      if string.byte(Key) == 81 or string.byte(Key) == 113 then
         Mode = Mode - 1
         if Mode < 0 then
            Mode = 1
         end
      elseif string.byte(Key) == 69 or string.byte(Key) == 101 then
         Mode = Mode + 1
         if Mode > 1 then
            Mode = 0
         end
      end
   end)
end)

You can also see it in solo mode at my place
Back to top Go down
Prodigy
Administrator
Administrator


Posts : 58
Join date : 2010-07-28

PostSubject: Re: Fun, fun....error -.-   August 2nd 2010, 11:17 pm

Try removing the "Local" when you first introduced "Mode"
Back to top Go down
http://roblox.youneed.us
Guest
Guest



PostSubject: Re: Fun, fun....error -.-   August 2nd 2010, 11:29 pm

That wouldn't do anything. The error isn't the variable, it is the mode itself. The mode is used to move your army. Mode 0 is to select them, but anyways...the error is when you try to move them up and down the ramp to the higher/lower area's of the map.
Back to top Go down
blueymaddog
Administrator
Administrator
avatar

Posts : 1081
Join date : 2010-12-09
Age : 19

PostSubject: Re: Fun, fun....error -.-   December 18th 2010, 9:04 am

Are you using a local script?

_________________
blueymaddog
Administrator • Moderator • Expert Scripter
PM: blueymaddog
<+1 post. ujelly?>
Back to top Go down
Supernapalm
Expert Scripter
Expert Scripter


Posts : 393
Join date : 2011-01-17

PostSubject: Re: Fun, fun....error -.-   January 18th 2011, 9:43 pm

geez... i dont think moving a part up and down a ramp has to be that complicated. what kind of coding style do you use? your script looks messy. im. sorry. its just. insane. at least put more comments...
Back to top Go down
http://hackthissite.org
Supernapalm
Expert Scripter
Expert Scripter


Posts : 393
Join date : 2011-01-17

PostSubject: Re: Fun, fun....error -.-   January 18th 2011, 9:44 pm

for example, this is just one of your lines of code:

Code:
 if Value.CFrame:pointToObjectSpace(Starting:lerp(Ending, Index / (Target - Start).magnitude)).x > -(Value.Size.x / 2) and Value.CFrame:pointToObjectSpace(Starting:lerp(Ending, Index / (Target - Start).magnitude)).x < (Value.Size.x / 2) and Value.CFrame:pointToObjectSpace(Starting:lerp(Ending, Index / (Target - Start).magnitude)).y > -(Value.Size.y / 2) and Value.CFrame:pointToObjectSpace(Starting:lerp(Ending, Index / (Target - Start).magnitude)).y < (Value.Size.y / 2) and Value.CFrame:pointToObjectSpace(Starting:lerp(Ending, Index / (Target - Start).magnitude)).z > -(Value.Size.z / 2) and Value.CFrame:pointToObjectSpace(Starting:lerp(Ending, Index / (Target - Start).magnitude)).z < (Value.Size.z / 2) then
Back to top Go down
http://hackthissite.org
Supernapalm
Expert Scripter
Expert Scripter


Posts : 393
Join date : 2011-01-17

PostSubject: Re: Fun, fun....error -.-   January 18th 2011, 9:45 pm

are you trying to make like a strategy game or something?
Back to top Go down
http://hackthissite.org
naknak
Administrator
Administrator
avatar

Posts : 878
Join date : 2010-07-30

PostSubject: Re: Fun, fun....error -.-   January 18th 2011, 10:09 pm

Everyone has there own way of coding. Like for me, I just go messy so no one can read it, but I still understand :)

I doubt Voidhack will get on this site anytime soon :(
Back to top Go down
Supernapalm
Expert Scripter
Expert Scripter


Posts : 393
Join date : 2011-01-17

PostSubject: Re: Fun, fun....error -.-   January 18th 2011, 10:45 pm

:( VoidHack is one of those scripters who use memory from what they learn. thats his style. i wonder how many programming books he reads. electronic or paper.
Back to top Go down
http://hackthissite.org
naknak
Administrator
Administrator
avatar

Posts : 878
Join date : 2010-07-30

PostSubject: Re: Fun, fun....error -.-   January 18th 2011, 10:47 pm

Probably a lot. You never builds, he literally builds his maps with scripts.
Back to top Go down
Supernapalm
Expert Scripter
Expert Scripter


Posts : 393
Join date : 2011-01-17

PostSubject: Re: Fun, fun....error -.-   January 18th 2011, 10:49 pm

hmm. i think i would chose the style for quality instead of ***. i often go for effeciency first.
Back to top Go down
http://hackthissite.org
naknak
Administrator
Administrator
avatar

Posts : 878
Join date : 2010-07-30

PostSubject: Re: Fun, fun....error -.-   January 18th 2011, 10:56 pm

I do, too. White space may be organized, but minimum space is the most efficient.
Back to top Go down
Supernapalm
Expert Scripter
Expert Scripter


Posts : 393
Join date : 2011-01-17

PostSubject: Re: Fun, fun....error -.-   January 18th 2011, 11:45 pm

hey what the. it blocked part of my chat. i was going to say messy instead of ***. lol. i didnt even notice that.
Back to top Go down
http://hackthissite.org
blueymaddog
Administrator
Administrator
avatar

Posts : 1081
Join date : 2010-12-09
Age : 19

PostSubject: Re: Fun, fun....error -.-   January 19th 2011, 6:42 am

lol

_________________
blueymaddog
Administrator • Moderator • Expert Scripter
PM: blueymaddog
<+1 post. ujelly?>
Back to top Go down
naknak
Administrator
Administrator
avatar

Posts : 878
Join date : 2010-07-30

PostSubject: Re: Fun, fun....error -.-   January 19th 2011, 8:02 pm

the forums are blocked too much sometimes. Of course, I don't like staring at the censored list so I can remove it >.<
Back to top Go down
blueymaddog
Administrator
Administrator
avatar

Posts : 1081
Join date : 2010-12-09
Age : 19

PostSubject: Re: Fun, fun....error -.-   January 20th 2011, 8:37 am

yea. I updated the site a bit! ;)

_________________
blueymaddog
Administrator • Moderator • Expert Scripter
PM: blueymaddog
<+1 post. ujelly?>
Back to top Go down
raboy117
Novice Scripter
Novice Scripter
avatar

Posts : 75
Join date : 2011-01-19
Age : 20
Location : Canada, PEI, Charlottetown

PostSubject: Re: Fun, fun....error -.-   January 20th 2011, 11:01 pm

Lol
Back to top Go down
raboy117
Novice Scripter
Novice Scripter
avatar

Posts : 75
Join date : 2011-01-19
Age : 20
Location : Canada, PEI, Charlottetown

PostSubject: Re: Fun, fun....error -.-   January 20th 2011, 11:01 pm

Lol
Back to top Go down
raboy117
Novice Scripter
Novice Scripter
avatar

Posts : 75
Join date : 2011-01-19
Age : 20
Location : Canada, PEI, Charlottetown

PostSubject: Re: Fun, fun....error -.-   January 20th 2011, 11:01 pm

Again???
Back to top Go down
blueymaddog
Administrator
Administrator
avatar

Posts : 1081
Join date : 2010-12-09
Age : 19

PostSubject: Re: Fun, fun....error -.-   January 22nd 2011, 12:08 am

i added to the cencored list. 0_o

_________________
blueymaddog
Administrator • Moderator • Expert Scripter
PM: blueymaddog
<+1 post. ujelly?>
Back to top Go down
Sponsored content




PostSubject: Re: Fun, fun....error -.-   

Back to top Go down
 
Fun, fun....error -.-
View previous topic View next topic Back to top 
Page 1 of 1
 Similar topics
-
» 2147287038 error, please help
» NTVDM Error
» -2147287038 (Unspecified Error 0x80030002) I d/c after a few minutes of playing!
» Error message when gifting
» gMotor 2 error when selecting a car

Permissions in this forum:You cannot reply to topics in this forum
A Roblox Community :: Questions and Help :: Scripting-
Jump to: