Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

the function should only runs if user has right mouse button held down on a button.How do i do it?

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)

3 comments

0

did you get this off a video?

0

nope

0

THIS QUESTION HAS BEEN ANSWERED BY ME

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

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.