Hi, I made 2 events. Carry event and Drop event. The carry event carries a carryable block and the drop event drops a block.
The problem is when 2 people are carrying a block, then one person drops the block, aka the drop event fires, it breaks the player’s block when they fire the drop event.
DropEvent Client | Local Script
local StarterGUI = game:GetService("StarterGui")
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
--local MobileButtonFrame = LocalPlayer.PlayerGui.Mobile.Frame
local Status = Character:WaitForChild("Status")
local CarryingStatus = Status.Carrying
-- Keycodes
local DropKey = Enum.KeyCode.E
-- Events
local DropEvent = ReplicatedStorage.Events.Parts.Drop
CarryingStatus:GetPropertyChangedSignal("Value"):Connect(function() -- Fires when someones carrying something or not carrying
if CarryingStatus.Value == true then
if game:GetService("UserInputService").TouchEnabled and game:GetService("UserInputService").KeyboardEnabled == false then
LocalPlayer.PlayerGui.Mobile.Frame.Carry.Visible = true
else
LocalPlayer.PlayerGui.Mobile.Frame.Controls.Visible = true
end
else
if game:GetService("UserInputService").TouchEnabled and game:GetService("UserInputService").KeyboardEnabled == false then
LocalPlayer.PlayerGui.Mobile.Frame.Carry.Visible = false
else
LocalPlayer.PlayerGui.Mobile.Frame.Controls.Visible = false
end
end
end)
UserInputService.InputBegan:Connect(function(inputObject,gameProcessed) -- Handles all keyboard inputs.
if gameProcessed then return end
-- todo: Make drop key for PC.
if inputObject.KeyCode == DropKey and CarryingStatus.Value == true then
local Box = Character:WaitForChild("Box")
DropEvent:FireServer(Box)
end
end)
--todo: Make drop key for Mobile.
LocalPlayer.PlayerGui:FindFirstChild("Mobile").Frame.Carry.Activated:Connect(function(InputObject)
local Box = Character:WaitForChild("Box")
if CarryingStatus.Value == true then
CarryingStatus.Value = false
DropEvent:FireServer(Box)
end
end)
Server Events | Global Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
-- Events
local CarryEvent = ReplicatedStorage.Events.Parts.Carry
local DropEvent = ReplicatedStorage.Events.Parts.Drop
-- ETC
local CarryGUI = script.CarryGUI
local CarryID = script.Carry
local SoundsFolder = script.Sounds
function guiAnim(player,box)
local CarryGUIClone = CarryGUI:Clone()
if CarryGUIClone then
CarryGUIClone.Frame.TextLabel.Text = "You are now carrying: "..box:GetAttribute("Class")
CarryGUIClone.Parent = player.PlayerGui
CarryGUIClone.Notify:Play()
local Frame = CarryGUIClone.Frame
Frame.TextLabel:TweenPosition(UDim2.new(0.5, 0,0.02, 0),Enum.EasingDirection.Out,Enum.EasingStyle.Sine,4)
local Tween = TweenService:Create(
Frame.TextLabel,
TweenInfo.new(15,Enum.EasingStyle.Sine,Enum.EasingDirection.Out),
{TextTransparency = 1}
)
Tween:Play()
Tween.Completed:Connect(function()
CarryGUIClone:Destroy()
end)
end
end
CarryEvent.OnServerEvent:Connect(function(player,box)
if player.Character.Status.Carrying.Value == false then
player.Character.Status.Carrying.Value = true
CarryAnimation = player.Character:FindFirstChild("Humanoid").Animator:LoadAnimation(CarryID)
ProximityPrompt = box.ProximityPrompt
-- Handles Proximity
ProximityPrompt.MaxActivationDistance = 0
-- Handles Sound
print(SoundsFolder[box:GetAttribute("Class")].Name)
if SoundsFolder[box:GetAttribute("Class")] then -- Plays sound if attribute name is sound name.
SoundsFolder[box:GetAttribute("Class")]:Play()
SoundsFolder[box:GetAttribute("Class")]:Clone().Parent = box
end
-- Handles Animation
CarryAnimation.Looped = true
CarryAnimation:Play()
-- Handles Box
--box.CanCollide = false
box.Anchored = false
box.Parent = player.Character -- Used for drop key to find the box needed to drop.
box.Carry.Part1 = player.Character.HumanoidRootPart
-- GUI Handler
guiAnim(player,box)
end
end)
DropEvent.OnServerEvent:Connect(function(player,box)
print("DropEvent fired for ".. player.Name)
player.Character.Status.Carrying.Value = false
if CarryAnimation.IsPlaying then
CarryAnimation:Stop()
end
-- Box
box.Parent = workspace.PickableBoxes
box.Carry.Part1 = nil
ProximityPrompt.MaxActivationDistance = 5
end)