I will be extraordinarily happy if someone answers why this won't create a circular design
where it says -----------y pos---------, change the line above it, you should know all the variables and it goes into starterplayerscripts
function clamp(min,max,val)
return math.max(min,math.min(max,val))
end
local snap = 0.01 --defines the grid size(in studs)
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
mouse.TargetFilter = workspace.workingspace
local inv = player:WaitForChild('Inv')
local invgui = game.ReplicatedStorage.guistuff.Inventory:Clone()
invgui.Parent = player
local invloc = invgui.Parent
local isplacing = Instance.new('BoolValue',player)
isplacing.Name = 'placing'
isplacing.Value = false
local label = invgui.ImageButton
local buttonconnections = {}
function connectPlacing(v)
if v:IsA('GuiButton') then
local con
con = v.MouseButton1Down:connect(function()
if isplacing.Value == false and inv:FindFirstChild(v.Name).Value > 0 then
isplacing.Value = true
if player.PlayerGui:FindFirstChild('Inventory') then
player.PlayerGui.Inventory.Parent = player
end
local hitboxes = {}
for i, v in pairs(workspace.workingspace:GetChildren()) do
if v.ClassName == 'Model' then
local hitbox = Instance.new('SelectionBox',v.HitBox)
hitbox.Color3 = Color3.new(17,255,0)
hitbox.Adornee = v.HitBox
table.insert(hitboxes,hitbox)
end
end
local model = game.ReplicatedStorage.localitems:FindFirstChild(v.Name)
if model then
local nm = model:Clone()
nm.Parent = workspace.workingspace
for i, v in pairs(nm:GetChildren()) do
if v:IsA('BasePart') and v.Name ~= 'HitBox' then
v.Transparency = 0.25
v.CanCollide = false
elseif v.Name == 'HitBox' then
v.Transparency = 1
v.CanCollide = false
local outline = Instance.new('SelectionBox',v)
outline.Adornee = v
outline.Color3 = Color3.new(255,255,255)
end
end
local grid = game.ReplicatedStorage.Grid:Clone()
grid.Parent = workspace.workingspace
local hbsizey = nm.HitBox.Size.Y
local mp = mouse.Hit.p
local placepos = Vector3.new(clamp(-256,256,math.floor(mp.X/snap)*snap),100,hbsizey/2,clamp(-256,256,math.floor(mp.Z/snap)*snap))
local prevplacepos = placepos
local cur_angle = 0
local rotatecon
rotatecon = game:GetService('UserInputService').InputBegan:connect(function(i,v)
if i.KeyCode == Enum.KeyCode.R then
nm:SetPrimaryPartCFrame(nm.HitBox.CFrame * CFrame.Angles(0,math.rad(cur_angle+30),0))
cur_angle = cur_angle + 30
end
end)
local con
con = mouse.Button1Down:connect(function()
local placed = workspace.remotethings.place:InvokeServer(v.Name,placepos,cur_angle) --v.Name,placepos,cur_angle
if placed == true then
con:disconnect()
rotatecon:disconnect()
isplacing.Value = false
mouse.TargetFilter = nil
nm:Destroy()
grid:Destroy() -- v.Name is the items name so...
for i, v in pairs(hitboxes) do
if v then v:Destroy() end
end
end
end)
repeat wait()
mp = mouse.Hit.p
if isplacing.Value then
prevplacepos = placepos
placepos = Vector3.new(clamp(-341,-63,math.floor(mp.X/snap)*snap),100,clamp(-170,200,math.floor(mp.Z/snap)*snap))
grid:SetPrimaryPartCFrame(CFrame.new(placepos.X,100,placepos.Z)) ----------------------------------------changes y pos---------------------------
nm:SetPrimaryPartCFrame(CFrame.new(placepos) * CFrame.Angles(0,math.rad(cur_angle),0))
end
until isplacing.Value == false
end
end
end)
return con
else
return nil
end
end
local count = 0
for i, v in pairs(inv:GetChildren()) do
if v.Value > 0 then
local newlabel = label:Clone()
newlabel.Parent = invgui.Frame
newlabel.Position = UDim2.new(math.fmod(count,4)*0.25,0,math.floor(count/4)*0.125,0)
newlabel.Name = v.Name
newlabel.Visible = true
newlabel.Active = true
newlabel.ItemName.Text = v.Name
newlabel.ItemCount.Text = v.Value
end
count = count + 1
v.Changed:connect(function(h)
local c = #invgui.Frame:GetChildren()
if not invgui.Frame:FindFirstChild(v.Name) then
local newlabel = label:Clone()
newlabel.Parent = invgui.Frame
newlabel.Position = UDim2.new(math.fmod(c,4)*0.25,0,math.floor(c/4)*0.125,0)
newlabel.Name = v.Name
newlabel.Visible = true
newlabel.Active = true
newlabel.ItemName.Text = v.Name
newlabel.ItemCount.Text = v.Value
for i, v in pairs(buttonconnections) do
v:disconnect()
end
for a, b in pairs(invgui.Frame:GetChildren()) do
local con = connectPlacing(b)
table.insert(buttonconnections,con)
v.Changed:connect(function()
b.ItemCount.Text = inv:FindFirstChild(b.Name).Value
end)
end
end
end)
end
for i, v in pairs(invgui.Frame:GetChildren()) do
local con = connectPlacing(v)
table.insert(buttonconnections,con)
end
local gui = game.ReplicatedStorage.guistuff.ItemEdit
local remcon,sellcon = nil,nil
mouse.Button2Down:connect(function()
local t = mouse.Target
if t and t.Parent then
if t.Name == 'HitBox' and isplacing.Value == false then
if player.PlayerGui:FindFirstChild('ItemEdit') then
if remcon ~= nil then remcon:disconnect() end
if sellcon ~= nil then sellcon:disconnect() end
player.PlayerGui.ItemEdit:Destroy()
end
local newgui = gui:Clone()
newgui.Parent = player.PlayerGui
newgui.Frame.Position = UDim2.new(0,mouse.X,0,mouse.Y)
newgui.Frame:WaitForChild('ItemName').Text = t.Parent.Name
local discon
discon = mouse.Button1Down:connect(function()
newgui:WaitForChild('Frame')
local absx = newgui.AbsoluteSize.X --x size of the screen
local absy = newgui.AbsoluteSize.Y --y size of the screen
local msx = mouse.X/absx --the UDim2 xscale factor
local msy = mouse.Y/absy --the UDim2 yscale factor
local fsx = newgui.Frame.Size.X.Scale --the xscale of the frame
local fpx = newgui.Frame.Position.X.Scale
local fsy = newgui.Frame.Size.Y.Scale
local fpy = newgui.Frame.Position.Y.Scale
--just some variables to make the code less cluttered
local fx = fpx + fsx
local fy = fpy + fsy
if msx < fpx or msx > fx or msy < fpy or msy > fy then
discon:disconnect()
newgui:Destroy() --basically, if the player clicks somewhere not in the buttons, it destroys the gui
end
end)
local remcon0
remcon0 = game:GetService('UserInputService').InputBegan:connect(function(a,b)
if a.KeyCode == Enum.KeyCode.E then
remcon0:disconnect()
newgui.Frame:FindFirstChild('Remove').Text = 'Removing...'
local name = t.Parent.Name
local success = workspace.remotethings.removeitem:InvokeServer(t.Parent)
repeat wait() until success or success == -1
newgui:Destroy()
elseif a.KeyCode == Enum.KeyCode.T then
newgui.Frame:FindFirstChild('Sell').Text = 'Selling...'
remcon0:disconnect()
local name = t.Parent.Name
local success = workspace.remotethings.sellitem:InvokeServer(t.Parent)
repeat wait() until success or success == -1
newgui:Destroy()
end
end)
remcon = newgui.Frame:WaitForChild('Remove').MouseButton1Down:connect(function()
newgui.Frame:FindFirstChild('Remove').Text = 'Removing...'
local name = t.Parent.Name
local success = workspace.remotethings.removeitem:InvokeServer(t.Parent)
repeat wait() until success or success == -1
newgui:Destroy()
end)
sellcon = newgui.Frame:WaitForChild('Sell').MouseButton1Down:connect(function()
newgui.Frame:FindFirstChild('Sell').Text = 'Selling...'
local name = t.Parent.Name
local success = workspace.remotethings.sellitem:InvokeServer(t.Parent)
repeat wait() until success or success == -1
newgui:Destroy()
end)
end
end
end)
game:GetService('UserInputService').InputBegan:connect(function(i,v)
if i.KeyCode == Enum.KeyCode.F and isplacing.Value == false and not player.PlayerGui:FindFirstChild('Inventory') then
if not player.PlayerGui:FindFirstChild('Shop') then
local new = game.ReplicatedStorage.guistuff.Shop:Clone()
new.Parent = player.PlayerGui
new.ImageButton:Destroy()
else
player.PlayerGui.Shop:Destroy()
end
elseif i.KeyCode == Enum.KeyCode.G and isplacing.Value == false and not player.PlayerGui:FindFirstChild('Shop') then
if not player.PlayerGui:FindFirstChild('Inventory') then
invgui.Parent = player.PlayerGui
else
invgui.Parent = invloc
end
end
end)
--[[the box that appears when you hover your mouse over a placed item]]--
local box
while wait() do
if box then box:Destroy() end
local t = mouse.Target
if t then
if t.Name == 'HitBox' and isplacing.Value == false then
box = Instance.new('SelectionBox',t)
box.Adornee = t
box.Color3 = Color3.new(0,255,0)
end
end
end
thanks, but litterally 99.9999% of the people who see this won't help at all, i don't even think BlueTaslem can fix this, just any pro, i need help
this is what I want you guys to do, if you can make the snap to grid place within a circle, it'd be great, here is what you should change
placepos = Vector3.new(clamp(-341,-63,math.floor(mp.X/snap)*snap),100,clamp(-170,200,math.floor(mp.Z/snap)*snap))

3 comments
Google it LMAO
Please create appropriate titles for your questions. The title should be a short summary of your question.
Why not just check for magnitude? Ez pz.