You are on page 1of 4

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Players = game:GetService("Players")


local TweenService = game:GetService("TweenService")
local RunService = game:GetService("RunService")

local Remotes = ReplicatedStorage:WaitForChild("Remotes")


local Builds = ReplicatedStorage:WaitForChild("Builds")

local Server = Remotes:WaitForChild("Server")


local Client = Remotes:WaitForChild("Client")

local Callbacks = Remotes:WaitForChild("Callbacks")

local Framework = workspace:WaitForChild("Framework")

local Properties = require(script:WaitForChild("PlacementProperties"))

local _isBuilding = false


local _canPlace = true

local _gridSize = 0.1


local _block = nil
local _blockCFrame = nil
local _animCFrame = nil
local _lastClicked = tick()

local placement = {}

local plr = nil


local mouse = nil
local char = nil

function tween(o,t,p)
return TweenService:Create(o,TweenInfo.new(1,Enum.EasingStyle.Cubic),p)
end

function transparency(o, v)
tween(o,1,{
Transparency = v
}):Play()

tween(o.UI.NoteUI, 1, {
BackgroundTransparency = v
}):Play()
end

if RunService:IsClient() then
-- Client Side
plr = Players.LocalPlayer
mouse = plr:GetMouse()
char = plr.Character or plr.CharacterAdded:Wait()

placement.Place = nil
else
placement.Place = function(...)
if not RunService:IsServer() then
return
end
local v = {...}

local plrName = v[1]


local objectName = v[2]
local cframe = v[3]
local preview_txt = v[4]

local _object = Builds:FindFirstChild(objectName)

warn("Received")

if _object then
warn("Cloning")

local clone = _object:Clone()


clone.Parent = Framework.Server
clone.CFrame = cframe * CFrame.Angles(0, 0, math.rad(math.random(-
8,8)))

clone.UI.NoteUI.Preview.Text = preview_txt
clone.UI.NoteUI.Autor.Text = string.format("By %s", plrName)
end
end
end

placement.StartDisplay = function(...)
local v = {...}

local can = Callbacks:InvokeServer("Check")

if not can then


return
end

local txt = v[1]

print(txt)

coroutine.wrap(function()
if not _isBuilding then
_isBuilding = true

warn("Doing")

_displayText = txt

_block = Builds.Note:Clone()
_block.Parent = Framework.Client
_block.UI.NoteUI.Preview.Text = _displayText
_block.UI.NoteUI.Autor.Text = string.format("By %s", plr.Name)

transparency(_block, .5)

local yOrientation = 0
local ignoreList = {char, _block, Framework.Server}

while _isBuilding and _block do

--[[
local _rayParams = RaycastParams.new()
_rayParams.FilterDescendantsInstances = {char;_block}
_rayParams.IgnoreWater = true
_rayParams.FilterType = Enum.RaycastFilterType.Blacklist

local _unitRay = mouse.UnitRay


local _origin, _direction = _unitRay.Origin, _unitRay.Direction
* 100000
--]]
local instance, position, target, normal =
Properties.getMousePoint(ignoreList)

--local _result = workspace:Raycast(_origin, _direction,


_rayParams)

if instance then
if position then
--local pos = _result.Position
--_blockCFrame = CFrame.new(math.floor(pos.X / _gridSize) *
_gridSize, pos.Y + _block.Size.Y/2,math.floor(pos.Z / _gridSize) * _gridSize)

task.spawn(function()
local _touched = _block:GetTouchingParts()
local _detected = false

for _, part in next, _touched do


if part:IsDescendantOf(Framework.Server) then
_detected = true
end

task.wait()
end

if _detected then
_canPlace = false
else
_canPlace = true
end

if _canPlace then
tween(_block, .35, {
Color = Color3.fromRGB(155, 255, 175)
}):Play()
else
tween(_block, .35, {
Color = Color3.fromRGB(255, 88, 88)
}):Play()
end
end)

--_blockCFrame = CFrame.new(position) * CFrame.Angles(0,


math.rad(yOrientation), 0)

_blockCFrame = CFrame.new(position, position + normal)


_animCFrame = _block.CFrame:Lerp(_blockCFrame,1/1.5)
_block.CFrame = _animCFrame
end
end
task.wait()
end

warn("Stopped")
end
end)()
end

placement.PlaceRequest = function(...)
warn("Place request")

print(_canPlace,_block,_blockCFrame)

local dif = tick() - _lastClicked


print(dif)

if _canPlace and _block and _blockCFrame ~= nil and dif > 1 then
warn("Success")

_lastClicked = tick()

Callbacks:InvokeServer("Place", _block.Name, _blockCFrame, _displayText)

transparency(_block, 0)

_canPlace = false
_isBuilding = false
_block:Destroy()
_blockCFrame = nil
_animCFrame = nil
_displayText = nil
end
end

return placement

You might also like