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

Why is UserInputService.InputBegan:Connect(function(input) not working how i want it to?

Asked by 3 years ago

there are two of the bellow scripts one for each label. but for some reason the image for the drag label dosent change? why? and also why can i click and drag outside the label?

local UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local info = script.Parent.Parent.Parent.InvStats
local hold = info.Holding
local slot = info.Slot
script.Parent.MouseEnter:Connect(function()
    if hold.Value == true then
        local invslots = script.Parent.Parent:GetChildren()
        for i, v in pairs(invslots) do
            if v.Name == "InvSlot" then
                if not v.SlotNumber.Value == slot.Value then
                    print(v.Name)
                    print(v.SlotNumber.Value)
                    if info.Occupid.Value == true then
                        if not v.SlotNumber.Value == script.Parent.SlotNumber.Value then
                            print(v.Name)
                            print(v.SlotNumber.Value)
                            local infoclone = v.Info.ItemTemplate:Clone()
                            infoclone.Parent = script.Parent.Info
                            v.Info.ItemTemplate:Destroy()
                        end
                    end
                end
            else
                hold.Value = true
            end
        end
    else
        UserInputService.InputBegan:Connect(function(input)
            if input.UserInputType == Enum.UserInputType.MouseButton1 then
                hold.Value = true
                slot.Value = script.Parent.SlotNumber.Value
                info.Occupid.Value = script.Parent.Occupid.Value
                info.Image.Value = script.Parent.Image
            end
        end)
    end
end)
script.Parent.MouseLeave:Connect(function()
    UserInputService.InputEnded:Connect(function(input)
        local inputType = input.UserInputType
        if inputType == Enum.UserInputType.MouseButton1 then
            hold.Value = false
            info.Occupid.Value = false
        end
    end)
end)

^^main script the one in each label^^

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
while true do
    if script.Parent.Parent.InvStats.Holding.Value == true then
        script.Parent.ImageLabel.Position = UDim2.new(0,mouse.X - 80,0,mouse.Y - 100)
        script.Parent.ImageLabel.Visible = true
        script.Parent.ImageLabel.Image = script.Parent.Parent.InvStats.Image.Value
    else
        script.Parent.ImageLabel.Visible = false
    end
    wait()
end

^^script that controls the label at the mouse vid : https://streamable.com/ak345k

1 answer

Log in to vote
0
Answered by 3 years ago

It seems you are using UIS for Mouse Keybinds, in that case you Mouse.KeyDown

https://developer.roblox.com/en-us/api-reference/event/Mouse/KeyDown

???(ignore the lable talking about uis, i would always use KeyDown for mouse stuff)???

Example: (LocalScript)

local hold
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse() 

mouse.Button1Down:Connect(function()
    hold = true
end

mouse.Button1Up:Connect(function()
    hold = false
end
--little extra thing that prints 'true' when it detects youre holding left click, use this for debugging.
while true do
    wait(0.5)
    print(hold)
end

If there's any problems, let me know

Note: This is my first answer, feedback would be nice.

0
Meant to type 'use' instead of 'you' in the first sentence, my bad. AaronWilhelm -2 — 3y
0
it dosent work in a gui marsdonh 36 — 3y
Ad

Answer this question