Bloxthard
(Bloxthard)
January 1, 2022, 3:47pm
#1
Hello again! I need help in a code. The code only runs when the game runs. If I disable it, then enable it, it has the same problem. Any help?
Code:
local part1 = workspace.Part1.Position
local part2 = workspace.Part2.Position
local direction = part1 - part2
local part = Instance.new("Part")
part.CFrame = CFrame.new(part1 + direction/2, partb)
part.Size = Vector3.new(1, 0.001, direction.Magnitude)
part.Parent = workspace
part.Anchored = true
local Decal = Instance.new("Decal",part)
Decal.Texture = "http://www.roblox.com/asset/?id=8401859970"
Decal.Face = "Top"
wf_sh
(wait)
January 1, 2022, 3:49pm
#2
How often do you want this code to run? by default when the server starts all scripts are run and once they reach the end they stop. This is also better placed in Scripting Suppport instead of game design support
Bloxthard
(Bloxthard)
January 1, 2022, 4:04pm
#3
I want it to run when the script finds part1 and part2 in the workspace.
hasanchik
(hasanchik)
January 1, 2022, 4:35pm
#4
Ever heard of waitforchild()? Its the exact thing you’re looking for.
local part1 = workspace:WaitForChild("Part1").Position
local part2 = workspace:WaitForChild("Part2").Position
local direction = part1 - part2
local part = Instance.new("Part")
part.CFrame = CFrame.new(part1 + direction/2, partb)
part.Size = Vector3.new(1, 0.001, direction.Magnitude)
part.Parent = workspace
part.Anchored = true
local Decal = Instance.new("Decal",part)
Decal.Texture = "http://www.roblox.com/asset/?id=8401859970"
Decal.Face = "Top"
Bloxthard
(Bloxthard)
January 1, 2022, 4:48pm
#5
I tried adding it, but when I run it, it just doesn’t work.
i think there’s a typo on line 6 of that code, try changing “partb” to “part2” and it should work.
NyrionDev
(Nyrion)
January 1, 2022, 5:32pm
#7
If you want the script to wait for an infinite amount of time, until it finds the parts, you can try workspace:WaitForChild("Part1", math.huge)
(same goes for Part2
).
Bloxthard
(Bloxthard)
January 1, 2022, 5:42pm
#8
It doesn’t work. Maybe because we all misunderstood the question.
When a player clicks the left mouse button, part1 creates. Then when a plyer clicks the right mouse part, part 2 creates. After enabling the script, nothing happens.
But ur script says the part is already in workspace also how do u know if part1 is named part1 it could just be called part
why dont u just do onchildadded event
Bloxthard
(Bloxthard)
January 1, 2022, 6:17pm
#10
I checked the part so it’s called part1