Hi there, I have a script where if you hit a key, such as “R” it fires a function however I want it to also allow clicks from a gui too and fire the same function, if that makes sense?
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)