What is happening and how do I fix this

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)

I think I found the problem:

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)

In here, if someone else is carrying it and they trigger the prompt, it will fire because the conditions are true

I don’t know how to fix this

If you don’t want another person to grab the block when someone is carrying it, then try to disable the proximity prompt until the player carrying the block drops it. :+1:

proximityPrompt.Enabled = false

&

proximityPrompt.Enabled = true

1 Like

I didn’t know that was a feature, does this stop ProximityService too?

check if the player is the local player??

I might be wrong, but about the animation error, it may be because the CarryAnimation gets overridden by someone that carried the box, considering the fact that the animation is operated on a server script.

If that’s the case, you may wanna do CarryAnimation[player] instead, which creates some sort of data, so that the DropEvent can be more specific with players and its CarryAnimation.

Same with the ProximityPrompt.

Here is the CarryEvent.

CarryEvent.OnServerEvent:Connect(function(player,box)
	player.Character.Status.Carrying.Value = true
	CarryAnimation[player] = player.Character:FindFirstChild("Humanoid").Animator:LoadAnimation(CarryID)
	ProximityPrompt[player] = box.ProximityPrompt
	-- Handles Proximity
	ProximityPrompt[player].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[player].Looped = true
	CarryAnimation[player]: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)

And the DropEvent.

DropEvent.OnServerEvent:Connect(function(player,box)
	player.Character.Status.Carrying.Value = false
	if CarryAnimation[player].IsPlaying then
		CarryAnimation[player]:Stop()
	end
	-- Box
	box:SetAttribute("Carryable",true) 
	box.Parent = workspace.PickableBoxes
	box.Carry.Part1 = nil
	ProximityPrompt[player].MaxActivationDistance = 5
end)

Hopefully this solves your problem, and if you see any error, let me know.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.