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

:80 How to Fix Attempt to index nil with 'InputBegan'?

Asked by 3 years ago
Edited 3 years ago
local player = game.Players.LocalPlayer
 for i,v in pairs(player.PlayerGui:GetChildren()) do
        if v.Name == "ScreenGui" then
            v:Destroy()
        end
    end
for i,v in pairs(player.Character.HumanoidRootPart:GetChildren()) do
        if v.Name == "Music" then
            v:Destroy()
        end
    end
local music = Instance.new("Sound")
music.Name = "Music"
music.Parent = player.Character.HumanoidRootPart
music.SoundId = "rbxassetid://5141421709"
music.Volume = 2
music:Play()
local ScreenGui = Instance.new("ScreenGui")
local Frame = Instance.new("Frame")
local TextLabel = Instance.new("TextLabel")
local TextButton = Instance.new("TextButton")
local TextButton_2 = Instance.new("TextButton")
local TextButton_3 = Instance.new("TextButton")
local TextButton_4 = Instance.new("TextButton")


Frame.Parent = ScreenGui
Frame.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
Frame.Position = UDim2.new(0, 5, 0, -5)
Frame.Size = UDim2.new(0, 200, 0, 300)
Frame.BackgroundTransparency = 1

TextLabel.Parent = Frame
TextLabel.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
TextLabel.Size = UDim2.new(0, 200, 0, 60)
TextLabel.Font = Enum.Font.AmaticSC
TextLabel.Text = "Project XL"
TextLabel.TextColor3 = Color3.fromRGB(255, 255, 255)
TextLabel.TextScaled = true
TextLabel.TextSize = 35.000
TextLabel.TextWrapped = true

ScreenGui.Parent = game.Players.LocalPlayer:WaitForChild("PlayerGui")

local UserInputService = game:GetService("UserInputService")

local MainFrame = frame
local TopBar = TextLaber

local Camera = workspace:WaitForChild("Camera")

local DragMousePosition
local FramePosition

local Draggable = false

TopBar.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
Draggable = true
DragMousePosition = Vector2.new(input.Position.X, input.Position.Y)
FramePosition = Vector2.new(MainFrame.Position.X.Scale, MainFrame.Position.Y.Scale)
end
end)

TopBar.InputEnded:Connect(function()
if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
Draggable = false
end
end)

UserInputServerice.InputChanged:Connect(function()
local NewPosition = FramePosition + ((Vector2.new(input.Position.X, input.Position.Y) - DragMousePostion) / Camera.ViewportSize)
MainFrame.Position = UDim2.new(NewPosition.X, 0, NewPosition.Y, 0)
end)

1 answer

Log in to vote
0
Answered by
oSudden 20
3 years ago

So you have quite a few naming errors in there but your main problem is that you're using the wrong variables.

local player = game.Players.LocalPlayer
 for i,v in pairs(player.PlayerGui:GetChildren()) do
        if v.Name == "ScreenGui" then
            v:Destroy()
        end
    end
for i,v in pairs(player.Character.HumanoidRootPart:GetChildren()) do
        if v.Name == "Music" then
            v:Destroy()
        end
    end
local music = Instance.new("Sound")
music.Name = "Music"
music.Parent = player.Character.HumanoidRootPart
music.SoundId = "rbxassetid://5141421709"
music.Volume = 2
music:Play()
local ScreenGui = Instance.new("ScreenGui")
local Frame = Instance.new("Frame")
local TextLabel = Instance.new("TextLabel")
local TextButton = Instance.new("TextButton")
local TextButton_2 = Instance.new("TextButton")
local TextButton_3 = Instance.new("TextButton")
local TextButton_4 = Instance.new("TextButton")


Frame.Parent = ScreenGui
Frame.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
Frame.Position = UDim2.new(0, 5, 0, -5)
Frame.Size = UDim2.new(0, 200, 0, 300)
Frame.BackgroundTransparency = 1

TextLabel.Parent = Frame
TextLabel.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
TextLabel.Size = UDim2.new(0, 200, 0, 60)
TextLabel.Font = Enum.Font.AmaticSC
TextLabel.Text = "Project XL"
TextLabel.TextColor3 = Color3.fromRGB(255, 255, 255)
TextLabel.TextScaled = true
TextLabel.TextSize = 35.000
TextLabel.TextWrapped = true

ScreenGui.Parent = game.Players.LocalPlayer:WaitForChild("PlayerGui")

local UserInputService = game:GetService("UserInputService")

local MainFrame = frame
local TopBar = TextLabel

local Camera = workspace:WaitForChild("Camera")

local DragMousePosition
local FramePosition

local Draggable = false

UserInputService.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
Draggable = true
DragMousePosition = Vector2.new(input.Position.X, input.Position.Y)
FramePosition = Vector2.new(MainFrame.Position.X.Scale, MainFrame.Position.Y.Scale)
end
end)

UserInputService.InputEnded:Connect(function()
if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
Draggable = false
end
end)

UserInputService.InputChanged:Connect(function()
local NewPosition = FramePosition + ((Vector2.new(input.Position.X, input.Position.Y) - DragMousePostion) / Camera.ViewportSize)
MainFrame.Position = UDim2.new(NewPosition.X, 0, NewPosition.Y, 0)
end)

That should work, enjoy.

0
this should work WINDOWS10XPRO 438 — 3y
0
No it doesn't work 18193883 0 — 3y
Ad

Answer this question