Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago
Edited 4 years ago
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)

0
did you get this off a video? iiDevPanda 43 — 4y
0
nope mikey2019d 43 — 4y
0
THIS QUESTION HAS BEEN ANSWERED BY ME mikey2019d 43 — 4y

3 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Do a while true do when the held is true

For example

while held = true do
    --function here
end
0
Might need wait cause it could break from how fast this is running PixelRankYT 20 — 4y
0
Oh ok thank you, will try mikey2019d 43 — 4y
Ad
Log in to vote
0
Answered by
uhi_o 417 Moderation Voter
4 years ago

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

Log in to vote
0
Answered by 4 years ago
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)    


Answer this question