Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[ Item placement script
- -- Variables
- local StoredPart = script.Parent.StoredPart.Value
- local player = game.Players.LocalPlayer
- local playerGui = player.PlayerGui
- local char = player.Character
- local mouse = player:GetMouse()
- local isPlacing = false
- local canPlace = false
- local mouseCFrame = mouse.Hit
- local mouseX = mouseCFrame.X
- local mouseY = mouseCFrame.Y
- local mouseZ = mouseCFrame.Z
- -- Taking out the item, placing
- function placeItem()
- isPlacing = true
- StoredPart.Parent = workspace
- StoredPart.Transparency = 0.25
- StoredPart.CanCollide = false
- mouse.Button1Down:Connect(function()
- if canPlace == true then
- isPlacing = false
- StoredPart.Transparency = 0
- StoredPart.CanCollide = true
- StoredPart.Anchored = false
- script.Parent:Destroy()
- end
- end)
- end
- -- Moving the item being placed
- function moveItem()
- if isPlacing == true then
- StoredPart.Position = Vector3.new(mouseX, mouseY, mouseZ)
- else
- end
- end
- -- Allowing/not allowing placement
- function allowPlacement()
- local magnitude = (StoredPart.Position - char.Torso.Position).Magnitude
- if magnitude < 15 then
- canPlace = true
- elseif magnitude > 15 then
- canPlace = false
- end
- end
- -- Running placeItem()
- script.Parent.MouseButton1Down:Connect(placeItem)
- -- Running moveItem() & allowPlacement()
- mouse.Move:Connect(function()
- if isPlacing == true then
- wait(0.1)
- moveItem()
- allowPlacement()
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement