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)
function YourFunction(Name)
print("Hello "..tostring(Name)) -- Your Function
end
script.Parent.MouseButton1Click:Connect(function())
YourFunction("vxs")
end)
This script should be local script and parented in your gui dont forget that your gui need to be textbutton or imagebutton to work
and everytime you want to call the function you just need to write the name like this
function YourFunction(Name)
print("Hello "..tostring(Name)) -- Your Function
end
YourFunction("Yes")
Edit: Also using local script will affect only Client and i see you want achieve something which will be for server so i recommend you taking a look at this Remote Event This will allow you making changes for everyone using local script And with using it you just need to fire it when GUI being clicked