Hi! I made a carry event and a drop event, carry event is controlled by Proximity’s, drop event is controlled by the key E. So basically when 2 people carry a block, it works fine, but when someone drops the block, it bugs the block for some reason. And this only happens when another person is carrying a block. Here’s a video describing it and the output (no bugs)
As you can tell in the video, when one person drops the block, the other person’s animation stops and the person that dropped the block has the animation instead.
Server Handler | Global Script -> ServerScriptService
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(6,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)
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()
local Sound = SoundsFolder[box:GetAttribute("Class")]:Clone()
Sound.Parent = box
game.Debris:AddItem(Sound,Sound.TimeLength)
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)
DropEvent.OnServerEvent:Connect(function(player,box)
player.Character.Status.Carrying.Value = false
if CarryAnimation.IsPlaying then
CarryAnimation:Stop()
end
-- Box
box:SetAttribute("Carryable",true)
box.Parent = workspace.PickableBoxes
box.Carry.Part1 = nil
ProximityPrompt.MaxActivationDistance = 5
end)
Client Handler | Local Script -> StarterPlayerScripts
local ProximityPromptService = game:GetService("ProximityPromptService")
local StarterGUI = game:GetService("StarterGui")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local PartEvents = ReplicatedStorage.Events.Parts.Carry
local Player = Players.LocalPlayer
local Character = Player.Character or Player.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
local Debounce = false
-- Attributes
ProximityPromptService.PromptTriggered:Connect(function(proximityPrompt,playerWhoTriggered)
local Carryable = proximityPrompt:GetAttribute("Carryable")
local Box = proximityPrompt.Parent
local Status = Character:WaitForChild("Status")
if Carryable and Carryable == true and Status.Carrying.Value ~= true and not Debounce then
Debounce = true
Carryable = false
PartEvents:FireServer(Box)
wait(2)
Debounce = false
end
if Debounce == true and Status.Carrying.Value ~= true then
proximityPrompt.ObjectText = "Try again in 2s"
end
end)
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
Player.PlayerGui.Mobile.Frame.Carry.Visible = true
else
Player.PlayerGui.Mobile.Frame.Controls.Visible = true
end
else
if game:GetService("UserInputService").TouchEnabled and game:GetService("UserInputService").KeyboardEnabled == false then
Player.PlayerGui.Mobile.Frame.Carry.Visible = false
else
Player.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.
Player.PlayerGui:FindFirstChild("Mobile").Frame.Carry.Activated:Connect(function(InputObject)
local Box = Character:WaitForChild("Box")
if CarryingStatus.Value == true then
DropEvent:FireServer(Box)
end
end)