BunnlyYt
(BunnlyYt)
April 9, 2024, 12:29pm
#1
I have a script. The error is the title.
local floor: Vector3 = workspace:Raycast(position, Vector3.new(0,-5,0)).Position
Thats the piece of code where the error happens.
There’s another unsolved thing I need help on so it would be nice if you check it out.
SelDraken
(SelDraken)
April 9, 2024, 12:33pm
#3
Check to make sure you are actually getting a valid return on your raycast.
local result = workspace:Raycast(… )
if result ~= nil then
…
end
something like that.
BunnlyYt
(BunnlyYt)
April 9, 2024, 12:35pm
#4
Didn’t work. The problem is the raycast I’m sure.
BunnlyYt
(BunnlyYt)
April 9, 2024, 12:36pm
#5
Do you need the whole script? (limit)
SelDraken
(SelDraken)
April 9, 2024, 12:38pm
#6
When you say, ‘didn’t work’ do you mean…
That you tried it with an ‘if’ statement but it never reached the inside of the if?
Or do you mean that it gave an error still?
Also, yes, more code might be helpful.
BunnlyYt
(BunnlyYt)
April 9, 2024, 12:39pm
#7
Ok.
Tree.New = function(position: CFrame, tree: BasePart)
local newTree: BasePart = tree:Clone()
newTree.Size = Vector3.new(tree:GetAttribute("Thickness"),0.5,tree:GetAttribute("Thickness"))
local treeInside: BasePart = newTree:FindFirstChild("Inside") :: BasePart
treeInside.Size = Vector3.new(tree:GetAttribute("Thickness") - 0.1,0.5,tree:GetAttribute("Thickness") - 0.1)
local floor: Vector3 = workspace:Raycast(position, Vector3.new(0,-5,0)).Position
if(floor) then
floor -= Vector3.new(0,0.51,0)
newTree.Position = floor
local treeTiltValue: number = tree:GetAttribute("Tilt")
local rx, ry, rz: number = math.random(-treeTiltValue,treeTiltValue), math.random(-treeTiltValue,treeTiltValue), math.random(-treeTiltValue,treeTiltValue)
newTree.Rotation = Vector3.new(rx, ry, rz)
else
error("Raycast failed!")
end
end
SelDraken
(SelDraken)
April 9, 2024, 12:44pm
#8
I see you have ‘position’ coming in as a CFrame
However, I think the Raycast for the first parameter needs a Vector3
so maybe
workspace:Raycast(position.Position, Vector3.new(0,-5,0))
Also, I would do this…
local result = workspace:Raycast(position.Position, Vector3.new(0,-5,0))
if (result and result.Position) then
local floor = result.Position
floor -= Vector3.new(0,0.51,0)
newTree.Position = floor
local treeTiltValue: number = tree:GetAttribute("Tilt")
local rx, ry, rz: number = math.random(-treeTiltValue,treeTiltValue), math.random(-treeTiltValue,treeTiltValue), math.random(-treeTiltValue,treeTiltValue)
newTree.Rotation = Vector3.new(rx, ry, rz)
else
error("Raycast failed!")
end
BunnlyYt
(BunnlyYt)
April 9, 2024, 12:52pm
#9
Thanks! I should try looking at those areas more.
1 Like
system
(system)
Closed
April 23, 2024, 12:52pm
#10
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.