Category playing twice

So im making a basic compulsion menu where there is few buttons called {Sleep, Follow me, Stop breathing} so everytime i compel the dummy and click on 1 it says the message “Listen Dummy, You ned to stop breathing” something like that and for each button it has it’s own line so whenever i click on “N” the button to compel more than once the message gets sent twice and the server receives the event twice so basically everything will be sped up by x2 now let’s say im done with this dummy and i wanna go to another dummy when i compel the other dummy to maybe follow me the other dummy does it too.

So i know it has something related with disconnecting events but i tried that and it just doesn’t reconnect again so any help is really appreciated!

Script:

-- !strict

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local CompulsionE = ReplicatedStorage.Pastwork.Compulsion
local CompellingE2 = ReplicatedStorage.Pastwork.Compulsion2
local TweenService = game:GetService("TweenService")
local ChatService = game:GetService("Chat")
local RagdollEvent = ReplicatedStorage.Events.RagdollEvent
CompulsionE.OnServerEvent:Connect(function(Plr, TargetHum, Message)
local PlrChar = Plr.Character
	local TargetChar = TargetHum.Parent
	if Message.Parent.Name == "StopBreathing" then
		CompellingE2:FireClient(game:GetService("Players"):GetPlayerFromCharacter(PlrChar))
		PlrChar.HumanoidRootPart.Anchored = false
		ChatService:Chat(PlrChar, "Listen "..TargetChar.Name.." "..Message.Value)
		local OnBreathing
		OnBreathing = true
		task.spawn(function()
			while OnBreathing do
				task.wait()
				TargetHum:TakeDamage(.1)
			end
		end)
	elseif Message.Parent.Name == "FollowMe" then
		CompellingE2:FireClient(game:GetService("Players"):GetPlayerFromCharacter(PlrChar))
		PlrChar.HumanoidRootPart.Anchored = false
		ChatService:Chat(PlrChar, "Listen "..TargetChar.Name.." "..Message.Value)
		local OnFollowing 
		OnFollowing = true
		task.spawn(function()
			while OnFollowing do
				task.wait()
				TargetHum:MoveTo(PlrChar.HumanoidRootPart.Position)
			end
		end)
		task.wait(10)
		OnFollowing = false
	elseif Message.Parent.Name == "Sleep" then
		CompellingE2:FireClient(game:GetService("Players"):GetPlayerFromCharacter(PlrChar))
		PlrChar.HumanoidRootPart.Anchored = false
		ChatService:Chat(PlrChar, "Listen "..TargetChar.Name.." "..Message.Value)
		CompulsionE:FireClient(game:GetService("Players"):GetPlayerFromCharacter(TargetChar))
		RagdollEvent:FireClient(game:GetService("Players"):GetPlayerFromCharacter(TargetChar), TargetHum, true)
		wait(10)
		RagdollEvent:FireClient(game:GetService("Players"):GetPlayerFromCharacter(TargetChar), TargetHum, false)
	end
end)

CompellingE2.OnServerEvent:Connect(function(Plr, TargetHum)
	local PlrChar = Plr.Character
	local TargetChar = TargetHum.Parent
	local tween = TweenService:Create(PlrChar.HumanoidRootPart, TweenInfo.new(.3), {CFrame = CFrame.lookAt(TargetChar.HumanoidRootPart.Position - Vector3.new(0, 0, 3), TargetChar.Head.Position)})
	tween:Play()
	tween.Completed:Connect(function()
		PlrChar.HumanoidRootPart.Anchored = true
	end)
end)

local script:

-- !strict

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Char = Player.Character or Player.CharacterAdded:Wait()
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local CompellingE = ReplicatedStorage.Pastwork.Compulsion
local CompellingE2 = ReplicatedStorage.Pastwork.Compulsion2
local Debris = game:GetService("Debris")
local Mouse = Player:GetMouse()	
local Tweenservice = game:GetService("TweenService")
local Playerui = Player.PlayerGui
local CompulsionUi = Playerui:WaitForChild("CompulsionUi")
UserInputService.InputBegan:Connect(function(Input, IsTyping)
	if not IsTyping then
		if Input.KeyCode == Enum.KeyCode.N then
			local MouseTarget = Mouse.Target
			if not MouseTarget then return end
			if MouseTarget ~= nil then
				if MouseTarget.Parent:FindFirstChildWhichIsA("Humanoid") then
					local Target = MouseTarget.Parent:FindFirstChildWhichIsA("Humanoid")
					if Target ~= nil then
						CompellingE2:FireServer(Target)
						CompulsionUi.Background.Visible = true
						Tweenservice:Create(CompulsionUi.Background, TweenInfo.new(.5), {Position = UDim2.new(0.011, 0, 0.29, 0)}):Play()
						for i, CompulsionButton in pairs(CompulsionUi.Background.MainFrame.CompellingStuff:GetChildren()) do
							if CompulsionButton:IsA("TextButton") then
								CompulsionButton.Activated:Connect(function()
									CompellingE:FireServer(Target, CompulsionButton.Value)
								end)
							end
						end
					end
				end
			end
		end
	end
end)
1 Like

Is there no other local script receiving the events? I can’t find anything in the local script about ComplusionE2.OnClientEvent.

1 Like

Yeah well the other one is just a event that gives a ui that tells the target you have been compellled to sleep nothing too important happening there the concerning thing is whenever im done with a player and go to another and compel him something the chat service makes 2 chats and it compels the old player too so its like they are still connected

1 Like

Doesn’t really matter, it could have the bug so it’s best to send all of your code.

1 Like