local UIS = game:GetService("UserInputService")
local runService = game:GetService("RunService")
--local
local player = game.Players.LocalPlayer
local slider = script.Parent
local sliderbar = script.Parent.Parent
local Bckcolor = script.Parent.Parent.Color
local held = false
UIS.InputBegan:Connect(function(Input, Processed)
if Input.UserInputType == Enum.UserInputType.MouseButton1 then
held = true
end
end)
UIS.InputEnded:Connect(function(Input, Processed)
held = false
end)
runService.RenderStepped:Connect(function(delta)
if held then
local mousePos = UIS:GetMouseLocation().X
local Position = mousePos - sliderbar.AbsolutePosition.X
local step = (Position/sliderbar.AbsoluteSize.X)
if step >= 0 and step <= 1 then
Bckcolor.Size = UDim2.new(step,0,0,11)
slider.Position = UDim2.new(step,0,-1,0)
end
end
end)
COMMUNITY QUESTION
the function should only runs if user has right mouse button held down on a button.How do i do it?
3 answers
Do a while true do when the held is true
For example
while held = true do
--function here
end
2 comments
0
Might need wait cause it could break from how fast this is running
0
Oh ok thank you, will try
There is a RBXScriptSignal called Button2Down that comes with the mouse
game.Players.LocalPlayer:GetMouse().Button2Down:Connect(function()
print("Player is holding down right click")
end)
https://developer.roblox.com/en-us/api-reference/event/Mouse/Button2Down
local UIS = game:GetService("UserInputService")
local runService = game:GetService("RunService")
local SN = script.Parent.Parent.Parent.Parent.SoundNumber.Number
local player = game.Players.LocalPlayer
local slider = script.Parent
local sliderbar = script.Parent.Parent
local Bckcolor = script.Parent.Parent.Color
local part = script.Parent.Parent.Parent.range
local held = false
UIS.InputBegan:Connect(function(Input, Processed)
if Input.UserInputType == Enum.UserInputType.MouseButton1 then
part.MouseEnter:Connect(function()
slider.MouseButton1Down:Connect(function()
held = true
end)
end)
end
end)
UIS.InputEnded:Connect(function(Input, Processed)
part.MouseLeave:Connect(function()
slider.MouseButton1Up:Connect(function()
held = false
end)
end)
end)
runService.RenderStepped:Connect(function(delta)
if held then
local mousePosX = UIS:GetMouseLocation().X
local Position = mousePosX - sliderbar.AbsolutePosition.X
local step = (Position/sliderbar.AbsoluteSize.X)
local number = tonumber(string.format("%.2f",step))*100
if step >= 0 and step <= 1 then
if number == 99 then
SN.Text = 100
else
SN.Text = number
end
Bckcolor.Size = UDim2.new(step,0,0,11)
slider.Position = UDim2.new(step,0,-1,0)
end
end
end)
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
did you get this off a video?
nope
THIS QUESTION HAS BEEN ANSWERED BY ME