Hi, im trying to make a script that lets ppl place a model and after placing when you hover over the model a billboardgui should pop up. The model placing works but the gui doesnt show up. The script is in a local script in startergui
local ui = game:GetService("UserInputService")
local rs = game:GetService("ReplicatedStorage")
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local m
local increment = 1
local d = false
local c = false
local mt
local function getCenter(model)
local p = Vector3.new()
local av = 0
for i, v in pairs(model:GetChildren()) do
if v:IsA('BasePart') then
av = av + 1
p = p + v.Position
end
end
return p / av
end
local function ray(pos, object)
local r = Ray.new(pos + Vector3.new(0, .1, 0), Vector3.new(0, -10, 0))
local hit, pos = workspace:FindPartOnRay(r, object)
return hit
end
local function checkDirections(center, size, object)
local left, right = center - Vector3.new(size.X) / 2, center + Vector3.new(size.X) / 2
local down = center - Vector3.new(0, size.Y) / 2
local back, front = center - Vector3.new(0, 0, size.Z) / 2, center + Vector3.new(0, 0, size.Z) / 2
if not ray(left, object) then return end
if not ray(right, object) then return end
if not ray(down, object) then return end
if not ray(back, object) then return end
if not ray(front, object) then return end
return true
end
local function round(v3)
local x = v3.X - (v3.X % increment)
local y = v3.Y - (v3.Y % increment)
local z = v3.Z - (v3.Z % increment)
return Vector3.new(x, y, z)
end
local center
wait(0.2)
local bgui
mouse.Move:Connect(function()
mt = mouse.Target
if mt ~= nil then
if mt.Parent.Name == "Box" then
if mt.Parent.Active.Value == true then
mt.Parent.BillboardGui.Enabled = true
bgui = mt.Parent
end
else
if bgui ~= nil then
bgui.BillboardGui.Enabled = false
end
end
end
end)
script.Parent.Shop.Frame.TextButton.MouseButton1Click:Connect(function()
c = false
m = rs.Stuff.Box:Clone()
m.Parent = workspace
m.Part.CanCollide = false
mouse.TargetFilter = m
m.Part.Anchored = true
center = getCenter(m)
mouse.Move:Connect(function()
if c == false then
if mouse.Target then
if mouse.Target.Name == "UserBase" then
local oldPosition = round(center)
local newPos = round(mouse.Hit.p)
m:MoveTo(newPos)
if not checkDirections(getCenter(m), m:GetExtentsSize(), m) then
--warn('Moving back')
m:MoveTo(oldPosition)
else
--print('Moving forward')
m:MoveTo(newPos)
center = getCenter(m)
end
wait()
mouse.Button1Down:Connect(function()
if mouse.Target.Name == "UserBase" and d == false then
d = true
m.Active.Value = true
m.Parent = workspace.Base
c = true
d = false
end
end)
end
end
end
end)
end)
