Mysterious error causes MouseButtonClick to not work - recently it was working

Hello there, one of my functions have broke randomly without any errors in the console, I’ve tried printing a message and it works but for some reason the variables I defined and the events have stopped working randomly. What the hell happened? There’s meant to have a event respond to a click when the guibutton is clicked and it worked before, but now it doesn’t. I haven’t had any changes done to the script.

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:wait()
local Humanoid = Character:WaitForChild("Humanoid")
local ragdollbutton = Player:WaitForChild("PlayerGui"): FindFirstChild("Toggle ragdoll")
local button = ragdollbutton:WaitForChild("ImageButton")
local ClickDetector = Instance.new("ClickDetector")

local Modules = script.Parent:WaitForChild("Modules")
--local Rig = require(Modules:WaitForChild("Rig"))
local Addons = require(Modules:WaitForChild("Addons"))
--local Settings = require(Modules:WaitForChild("Settings"))

local Events = script.Parent:WaitForChild("Events")
local Events_Toggle = Events:WaitForChild("Toggle")
local Events_GuiToClient = Events:WaitForChild("GuiToClient")

local Functions = script.Parent:WaitForChild("Functions")
--local Functions_Ragdoll = Functions:WaitForChild("Ragdoll")
local Functions_RemoteRagdoll = Functions:WaitForChild("RemoteRagdoll")
local Functions_RemoteVelocity = Functions:WaitForChild("RemoteVelocity")

local Variables = script.Parent:WaitForChild("Variables")
local Variables_Ragdoll = Variables:WaitForChild("Ragdoll")
local Variables_RagdollClient = Variables:WaitForChild("RagdollClient")

Toggle Ragdoll (Read last lines)

function ToggleVariables(mode)
	if mode == "R" then
		Events_Toggle:FireServer("R", not Variables_RagdollClient.Value)
	elseif mode == "L" then
		Events_Toggle:FireServer("L")
	end
end

Events_GuiToClient.Event:Connect(ToggleVariables)

game:GetService("ContextActionService"):BindAction("RagdollToggle", function(_,input)
	if input == Enum.UserInputState.Begin then
		ToggleVariables("R")
	end
end, false, Enum.KeyCode.R)

game:GetService("ContextActionService"):BindAction("ResetHotkey", function(_,input)
	if input == Enum.UserInputState.Begin then
		ToggleVariables("L")
	end
end, false, Enum.KeyCode.L)

button.MouseButton1Click:Connect(function()
	ToggleVariables("R")
	print ("Ragdoll")
end)
1 Like

Try MouseButton1Down, sometimes MouseButton1Click doesn’t work.

This may or may not be helpful, but if this is a local script(mostly likely is) then in the first few lines of the script you should add:

repeat wait() until game:IsLoaded()

This makes it so the script will run once everything in the client has been loaded.

Forgot to mention not even the keybinds work (Press R to toggle ragdoll)

should i add it after the locals?

Add it before all the local variables.

nope still aint working. i dont know what happened, even the vairables dont work

alright this is weird, I transferred the scripts to another game and it works

That’s really weird. What do you plan on doing now?

not sure, ill just create another game with the same stuff then :confused: