PadQueue Problem

Hello.

So I’m moving on into creating my own game! everything has been going smooth so far but I’ve ran into a major problem that isn’t really making sense to me.

When first hopping onto a pad then proceeding to hop off the values don’t reset themselves and I’m confused why that’s happening. Cause if I hop onto the other pad and hop off everything works perfectly.

The problem occurs when I trying on both pads and I’m completely clueless on what’s going on or how to fix it.

– Pictures

Pad:
image

When First Hopping On & Off:

Same thing but with the other pad:

– Code

-- Services --
local Players = game:GetService('Players')
----

-- On Joined/Added --
Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAppearanceLoaded:Connect(function(Character)
		-- Variables --
		local HumanoidRootPart = Character:FindFirstChild('HumanoidRootPart')
		local Humanoid = Character:FindFirstChild('Humanoid')
		-- For Statement --
		for _,Pad in ipairs(workspace.Map.Platforms:GetDescendants()) do
			-- On Walk/Enter Pad Check --
			if string.sub(Pad.Name,1,4) == 'Team' and Pad.Parent.Name == 'Queue' and Pad:IsA('Model') then
				Pad.Accent.Touched:Connect(function(Hit)
					-- Check --
					if not Hit.Parent:FindFirstChild('Humanoid') or not Hit.Parent:FindFirstChild('HumanoidRootPart') or not Pad.Parent.Parent:GetAttribute(Pad.Name .. 'Queueable',false) then return end
					-- Set/Change --
					Hit.Parent.Humanoid.WalkSpeed = 0
					Hit.Parent.HumanoidRootPart.CFrame = CFrame.new(Pad.Accent.Position.X,Hit.Parent.HumanoidRootPart.Position.Y,Pad.Accent.Position.Z)
					Hit.Parent.HumanoidRootPart.Orientation = Vector3.new(0,-90,0)
					Pad.Parent.Parent:SetAttribute(Pad.Name,Hit.Parent.Name)
					Pad.Parent.Parent:SetAttribute(Pad.Name .. 'Queueable',false)
				end)
				-- On Jump/Leave Pad Check --
				Humanoid:GetPropertyChangedSignal('Jump'):Connect(function()
					-- Check --
					if Humanoid.WalkSpeed == 0 then
						Humanoid.WalkSpeed = 16
						Pad.Parent.Parent:SetAttribute(Pad.Name,'')
						wait(2)
						Pad.Parent.Parent:SetAttribute(Pad.Name .. 'Queueable',true)
					end
				end)
			end
		end
	end)
end)
----

Pad is set in a for loop, the humanoid:GetPropertyChangedSignal(‘Jump’) never gets called on the same pad, it always gets called on the next one. In order to fix this:

for _,Pad in ipairs(workspace.Map.Platforms:GetDescendants()) do
			-- On Walk/Enter Pad Check --
			if string.sub(Pad.Name,1,4) == 'Team' and Pad.Parent.Name == 'Queue' and Pad:IsA('Model') then
				Pad.Accent.Touched:Connect(function(Hit)
                                local pad = Pad
					-- Check --
					if not Hit.Parent:FindFirstChild('Humanoid') or not Hit.Parent:FindFirstChild('HumanoidRootPart') or not Pad.Parent.Parent:GetAttribute(Pad.Name .. 'Queueable',false) then return end
					-- Set/Change --
					Hit.Parent.Humanoid.WalkSpeed = 0
					Hit.Parent.HumanoidRootPart.CFrame = CFrame.new(Pad.Accent.Position.X,Hit.Parent.HumanoidRootPart.Position.Y,Pad.Accent.Position.Z)
					Hit.Parent.HumanoidRootPart.Orientation = Vector3.new(0,-90,0)
					Pad.Parent.Parent:SetAttribute(Pad.Name,Hit.Parent.Name)
					Pad.Parent.Parent:SetAttribute(Pad.Name .. 'Queueable',false)
                                  -- On Jump/Leave Pad Check --
				Humanoid:GetPropertyChangedSignal('Jump'):Connect(function()
					-- Check --
					if Humanoid.WalkSpeed == 0 then
						Humanoid.WalkSpeed = 16
						pad.Parent.Parent:SetAttribute(pad.Name,'')
						wait(2)
						pad.Parent.Parent:SetAttribute(pad.Name .. 'Queueable',true)
					end
				end)
				end)
			end

I’d put the jump check inside the touched, or store the pad the player joined inside their player object.
That way, the pad always stays the same if you grab it from the variable.

1 Like

Hello, It appears that the issue may be coming from the Humanoid:GetPropertyChangedSignal('Jump'):Connect() event, which is located inside the Touched event of the pad. Because of this, each time the character touches a pad, a new Jump event gets connected to the character’s Humanoid, which could cause the issue of values not resetting, especially when the pads are touched in quick succession.

When you connect to a signal, the connection is not automatically disconnected when the signal triggers. As a result, every time a character touches a pad, a new connection is created, and each connection will trigger when the character jumps. This will most likely cause conflicting behavior as multiple events are firing and trying to reset values at the same time.

To fix this issue, you can disconnect the Jump event every time it fires. This will ensure that each touch will create a single jump event.

Here is an example of how to do this:

Pad.Accent.Touched:Connect(function(Hit)
    local pad = Pad
    -- Check --
    if not Hit.Parent:FindFirstChild('Humanoid') or not Hit.Parent:FindFirstChild('HumanoidRootPart') or not Pad.Parent.Parent:GetAttribute(Pad.Name .. 'Queueable',false) then return end
    -- Set/Change --
    local Humanoid = Hit.Parent.Humanoid
    Humanoid.WalkSpeed = 0
    Hit.Parent.HumanoidRootPart.CFrame = CFrame.new(Pad.Accent.Position.X,Hit.Parent.HumanoidRootPart.Position.Y,Pad.Accent.Position.Z)
    Hit.Parent.HumanoidRootPart.Orientation = Vector3.new(0,-90,0)
    Pad.Parent.Parent:SetAttribute(Pad.Name,Hit.Parent.Name)
    Pad.Parent.Parent:SetAttribute(Pad.Name .. 'Queueable',false)

    -- On Jump/Leave Pad Check --
    local jumpConnection
    jumpConnection = Humanoid:GetPropertyChangedSignal('Jump'):Connect(function()
        -- Check --
        if Humanoid.WalkSpeed == 0 then
            Humanoid.WalkSpeed = 16
            pad.Parent.Parent:SetAttribute(pad.Name,'')
            wait(2)
            pad.Parent.Parent:SetAttribute(pad.Name .. 'Queueable',true)
        end
        -- Disconnect the event here
        jumpConnection:Disconnect()
    end)
end)

In this code, I stored the connection from GetPropertyChangedSignal('Jump'):Connect() in a local variable called jumpConnection , then disconnect the connection in the connected function itself once it’s done executing. This way, you avoid having multiple “jump” events attached to a single Humanoid object, which is most likely the cause of your issue.

2 Likes

Thank you so much bro. I’ve been stuck on how to fix it for the past 3 days :sob:

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