Hello there, instead of wanting my script to fire an event when a key is clicked, I want it to fire of a mouseclick. How would I make this work?
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:wait()
local Humanoid = Character:WaitForChild("Humanoid")
local ragdollbutton = game.StarterGui["Toggle ragdoll"]
local button = ragdollbutton:WaitForChild("ImageButton")
local ClickDetector = Instance.new("ClickDetector")
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)
local ImageButton = the image button
local function Fire()
--bla bla bla
end
ImageButton.MouseButton1Click:Connect(Fire)
ImageButton.MouseButton2Click:Connect(Fire)
Is this correct because it doesn’t do anything at all when the guibutton is clicked (yes its a imagebutton)
read the 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")
end)```