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: Help with a script inside GUI

Previous Thread :: Next Thread 
TealTeam is not online. TealTeam
Joined: 06 Jan 2015
Total Posts: 720
28 Jul 2015 03:52 PM
Here's the script:

definition = 10
bc = {}
function Clicked()
function drawbezier(p,d)
local p=points
local d=definition
game.Workspace.CurTrack:ClearAllChildren()
for i=1,d do
local t = i/d
bc[i] = p[1]*(1-t)^2+2*p[2]*(1-t)*t+p[3]*t^2
end
for i=1,d do
local bcp = Instance.new("Part")
bcp.FormFactor = Enum.FormFactor.Custom
bcp.Anchored = true
if i ~= 1 then
bcp.CFrame = CFrame.new(bc[i]:Lerp(bc[i-1],0.5),bc[i])*CFrame.Angles(math.pi/2,0,0)
bcp.Size = Vector3.new(3,(bc[i]-bc[i-1]).magnitude,1)
else
bcp.CFrame = CFrame.new(bc[i]:Lerp(p[1],0.5),bc[i])*CFrame.Angles(math.pi/2,0,0)
bcp.Size = Vector3.new(3,(bc[i]-p[1]).magnitude,1)
end
bcp.Parent = game.Workspace.Tracks
end
end
end
points = {game.Workspace.CurPoints.A,game.Workspace.CurPoints.B,game.Workspace.CurPoints.C}

game.Workspace.CurPoints.A.Changed:connect(drawbezier)
game.Workspace.CurPoints.B.Changed:connect(drawbezier)
game.Workspace.CurPoints.C.Changed:connect(drawbezier)
script.Parent.MouseButton1Click:connect(Clicked)

Whenever I click it, the function doesn't run. There's no errors, but nothing happens. It's supposed to make a bezier curve from three points, but it doesn't get made. The other buttons in the GUI work, but this one doesn't. Is there somewhere I messed up? As I mentioned, there's no errors, so I cant imagine why it's doing this.
Report Abuse
sncplay42 is not online. sncplay42
Joined: 27 Nov 2008
Total Posts: 11891
28 Jul 2015 04:05 PM
drawbezier shouldn't be nested inside Clicked like that. Looks like what you want is to just remove Clicked and connect the mouse click event to drawbezier as well.
Report Abuse
membra is not online. membra
Joined: 14 Oct 2008
Total Posts: 6313
28 Jul 2015 04:05 PM
This is a total guess.

You define the drawbezier() function inside of Clicked(), but then attempt to attach it to an event before it is actually declared.

Again, total guess, it would probably have returned an error if this was the case.


[i like rhubarb]
Report Abuse
TealTeam is not online. TealTeam
Joined: 06 Jan 2015
Total Posts: 720
28 Jul 2015 04:09 PM
Thanks for the help! I figured it out!
Report Abuse
TealTeam is not online. TealTeam
Joined: 06 Jan 2015
Total Posts: 720
28 Jul 2015 04:16 PM
Hold up, I have another problem that I don't even know how to begin fixing. Here's my current script:

definition = 10
bc = {}
function drawbezier(p,d)
for i=1,d do
local t = i/d
bc[i] = p[1]*(1-t)^2+2*p[2]*(1-t)*t+p[3]*t^2
end
for i=1,d do
local bcp = Instance.new("Part")
bcp.FormFactor = Enum.FormFactor.Custom
bcp.Anchored = true
if i ~= 1 then
bcp.CFrame = CFrame.new(bc[i]:Lerp(bc[i-1],0.5),bc[i])*CFrame.Angles(math.pi/2,0,0)
bcp.Size = Vector3.new(3,(bc[i]-bc[i-1]).magnitude,1)
else
bcp.CFrame = CFrame.new(bc[i]:Lerp(p[1],0.5),bc[i])*CFrame.Angles(math.pi/2,0,0)
bcp.Size = Vector3.new(3,(bc[i]-p[1]).magnitude,1)
end
bcp.Parent = game.Workspace.Tracks
end
end

points = {game.Workspace.CurPoints.A,game.Workspace.CurPoints.B,game.Workspace.CurPoints.C}

script.Parent.MouseButton1Click:connect(drawbezier(points,definition))

The error im getting is:

17:14:51.855 - Players.Player.Backpack.BezCoaTool.BezCoaTool.Back.Curve.Cu:8: attempt to perform arithmetic on field '?' (a userdata value)
17:14:51.855 - Stack Begin
17:14:51.856 - Script 'Players.Player.Backpack.BezCoaTool.BezCoaTool.Back.Curve.Cu', Line 8
17:14:51.856 - Stack End

Any help?
Report Abuse
sncplay42 is not online. sncplay42
Joined: 27 Nov 2008
Total Posts: 11891
28 Jul 2015 04:18 PM
script.Parent.MouseButton1Click:connect(function() drawbezier(points,definition) end)
Report Abuse
sncplay42 is not online. sncplay42
Joined: 27 Nov 2008
Total Posts: 11891
28 Jul 2015 04:22 PM
Also what type of object is game.Workspace.CurPoints.(A/B/C)? On the line

bc[i] = p[1]*(1-t)^2+2*p[2]*(1-t)*t+p[3]*t^2

You use them as if they were numbers or Vector3s or whatever. You probably need to access their Value or Position property or something.
Report Abuse
TealTeam is not online. TealTeam
Joined: 06 Jan 2015
Total Posts: 720
28 Jul 2015 04:30 PM
This isn't my script, so I don't really know how it completely works. Also, i'm still getting the same error.
Report Abuse
TealTeam is not online. TealTeam
Joined: 06 Jan 2015
Total Posts: 720
28 Jul 2015 04:44 PM
bump, i really need this done soon
Report Abuse
sncplay42 is not online. sncplay42
Joined: 27 Nov 2008
Total Posts: 11891
28 Jul 2015 04:45 PM
Can you answer my question? I suspect you want

points = {game.Workspace.CurPoints.A.Position,game.Workspace.CurPoints.B.Position,game.Workspace.CurPoints.C.Position}

or

points = {game.Workspace.CurPoints.A.Value,game.Workspace.CurPoints.B.Value,game.Workspace.CurPoints.C.Value}
Report Abuse
TealTeam is not online. TealTeam
Joined: 06 Jan 2015
Total Posts: 720
28 Jul 2015 04:47 PM
They are Parts. Using the position still returns an error.
Report Abuse
TealTeam is not online. TealTeam
Joined: 06 Jan 2015
Total Posts: 720
28 Jul 2015 04:49 PM
Nevermind, I got it to work :D Thanks!
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