-
What do you want to achieve?
i want to make a system where you can split parts from where u click
-
What is the issue?
if the part is rotated it dosnt work properly
-
What solutions have you tried so far?
i cant find any solutions and i have no clue how to fix this
scripts:
-- local Script: --
local uis = game:GetService("UserInputService")
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
uis.InputEnded:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
if mouse.Hit and mouse.Target.Parent == game.Workspace.Parts then
print("Split")
local pos = Vector3.new(mouse.Target.Position.X,mouse.Hit.Y,mouse.Target.Position.Z)
game.ReplicatedStorage.Events.SplitPart:FireServer(pos,mouse.Target)
end
end
end)
-- Server Script: --
game.ReplicatedStorage.Events.SplitPart.OnServerEvent:Connect(function(plr,pos,part)
if part.Parent == game.Workspace.Parts then
local NewPart = Instance.new("Part")
NewPart.CFrame = part.CFrame
NewPart.Position = pos
NewPart.Size = Vector3.new(part.Size.X+0.1,0.2,part.Size.Z+0.1)
NewPart.Anchored = true
NewPart.Color = Color3.new(0,0,0)
NewPart.Parent = game.Workspace
local Attach1 = Instance.new("Attachment")
Attach1.Parent = part
Attach1.Position = Vector3.new(0,part.Size.Y/2,0)
local Attach2 = Instance.new("Attachment")
Attach2.Parent = part
Attach2.Position = Vector3.new(0, 0 - (part.Size.Y/2),0)
local part1 = part:Clone()
part1.Size = Vector3.new(part.Size.X,part.Size.Y - (pos - Attach2.WorldPosition).Magnitude,part.Size.Z)
part1.Position = Vector3.new(part.Position.X,pos.Y + (part1.Size.Y / 2),part.Position.Z)
part1.Anchored = true
part1.Color = Color3.new(1,0,0)
part1.Parent = game.Workspace.Parts
local part2 = part:Clone()
part2.Size = Vector3.new(part.Size.X,part.Size.Y - (pos - Attach1.WorldPosition).Magnitude,part.Size.Z)
part2.Position = Vector3.new(part.Position.X,pos.Y - (part2.Size.Y / 2),part.Position.Z)
part2.Anchored = true
part2.Color = Color3.new(0,1,0)
part2.Parent = game.Workspace.Parts
Attach1:Destroy()
Attach2:Destroy()
part:destroy()
end
end)
1 Like
nm i figured it out heres the new script if anyone has the same problem
--local script --
local uis = game:GetService("UserInputService")
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
uis.InputEnded:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
if mouse.Hit and mouse.Target.Parent == game.Workspace.Parts then
print("Split")
local pos = mouse.Hit.Position
local WorlPos = mouse.Target.CFrame:PointToObjectSpace(pos)
game.ReplicatedStorage.Events.SplitPart:FireServer(WorlPos,mouse.Target)
end
end
end)
--server script --
game.ReplicatedStorage.Events.SplitPart.OnServerEvent:Connect(function(plr,ClickPos,part,WorldPos)
if part.Parent == game.Workspace.Parts then
local attach = Instance.new("Attachment")
attach.Position = Vector3.new(0,ClickPos.Y,0)
attach.Parent = part
local pos = attach.WorldPosition
attach:Destroy()
local NewPart = Instance.new("Part")
NewPart.CFrame = part.CFrame
NewPart.Position = pos
NewPart.Size = Vector3.new(part.Size.X+0.1,0.2,part.Size.Z+0.1)
NewPart.Anchored = true
NewPart.Color = Color3.new(0,0,0)
NewPart.Parent = game.Workspace
local Attach1 = Instance.new("Attachment")
Attach1.Parent = part
Attach1.Position = Vector3.new(0,part.Size.Y/2,0)
local Attach2 = Instance.new("Attachment")
Attach2.Parent = part
Attach2.Position = Vector3.new(0, 0 - (part.Size.Y/2),0)
local middle = (Attach1.WorldPosition + NewPart.Position)/2
local part1 = part:Clone()
part1.Size = Vector3.new(part.Size.X,part.Size.Y - (pos - Attach2.WorldPosition).Magnitude,part.Size.Z)
part1.Position = middle
part1.Anchored = true
part1.Color = Color3.new(1,0,0)
part1.Parent = game.Workspace.Parts
middle = (Attach2.WorldPosition + NewPart.Position)/2
local part2 = part:Clone()
part2.Size = Vector3.new(part.Size.X,part.Size.Y - (pos - Attach1.WorldPosition).Magnitude,part.Size.Z)
part2.Position = middle
part2.Anchored = true
part2.Color = Color3.new(0,1,0)
part2.Parent = game.Workspace.Parts
Attach1:Destroy()
Attach2:Destroy()
part:destroy()
end
end)
system
(system)
Closed
#3
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.