You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
Hello, I want to achieve that I can drag the Player around inside Square around the Player. -
What is the issue? Include screenshots / videos if possible!
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
So far I tried scripting.
The scripts are all taking part inside this.
Place1.rbxl (60,1 KB)
The script
local Max_Distance = 6
local Connections = {}
local part = nil
local pos = nil
local mouse = game.Players.LocalPlayer:GetMouse()
local UIS = game:GetService("UserInputService")
game.ReplicatedStorage:WaitForChild("BroIsCookingSomething?")
game.ReplicatedStorage["BroIsCookingSomething?"].OnClientEvent:Connect(function(value,dragdetector : DragDetector )
local player = game.Players.LocalPlayer
local character = player.Character
local head = character:WaitForChild("Head")
if value then
part = dragdetector.Parent:WaitForChild('AlignPosition')
local boomer : AlignOrientation = dragdetector.Parent:WaitForChild('AlignOrientation')
Connections[dragdetector] = game:GetService("RunService").RenderStepped:Connect(function()
local MouseScreenPointPos = UIS:GetMouseLocation()
local ViewportMouseRay = workspace.CurrentCamera:ViewportPointToRay(MouseScreenPointPos.X, MouseScreenPointPos.Y)
local fakepos = ViewportMouseRay.Origin + ViewportMouseRay.Direction* (Max_Distance+(ViewportMouseRay.Origin-head.Position).Magnitude )
local actualpos = head.Position+ CFrame.new(head.Position,fakepos).LookVector *Max_Distance
if UIS:IsKeyDown(Enum.KeyCode.LeftControl) then
pos = actualpos
else
pos = ViewportMouseRay.Origin + ViewportMouseRay.Direction* (Max_Distance+(ViewportMouseRay.Origin-head.Position).Magnitude )
end
boomer.CFrame = CFrame.new(dragdetector.Parent.PrimaryPart.Position,head.Position)
end)
else
part = nil
pos = nil
if Connections[dragdetector] then
Connections[dragdetector]:Disconnect()
Connections[dragdetector] = nil
end
end
end)
game:GetService("RunService").RenderStepped:Connect(function()
if part and pos then
part.Position= pos
end
end)