Information:
Attempt:
local UIS = game:GetService("UserInputService") local player = game.Players.LocalPlayer local mouse = player:GetMouse() game.Players.PlayerAdded:Connect(function(player) UIS.InputChanged:Connect(function(input) if mouse.Target then if mouse.Target:FindFirstChild("BoolValue") then player.PlayerGui.CollectGUI.Enabled = true --ScreenGUI is enabled player.PlayerGui.CollectGUI.Frame.Position = UDim2.new(0, mouse.X, 0, mouse.Y) --Frame follows mouse player.PlayerGui.CollectGUI.Frame.ItemName.Text = mouse.Target.Parent.Name -- ItemName.Text is the part's name else player.PlayerGui.CollectGUI.Enabled = false --ScreenGUI is disabled player.PlayerGui.CollectGUI.Frame.Position = UDim2.new(0, 0, 0, 0) --Frame position is reset player.PlayerGui.CollectGUI.Frame.ItemName.Text = "" --ItemName.Text is reset end end end) end)
Why did you put UserInputService in this? We are needing the user's mouse, not keyboard clicks. There is also no need for the player added event since we know that local scripts run for the current player only. At least I hope you used a LocalScript which you must
local player = game.Players.LocalPlayer local mouse = player:GetMouse() if mouse.Target then if mouse.Target:FindFirstChild("BoolValue") then player.PlayerGui.CollectGUI.Enabled = true --ScreenGUI is enabled player.PlayerGui.CollectGUI.Frame.Position = UDim2.new(0, mouse.X, 0, mouse.Y) --Frame follows mouse player.PlayerGui.CollectGUI.Frame.ItemName.Text = mouse.Target.Parent.Name -- ItemName.Text is the part's name else player.PlayerGui.CollectGUI.Enabled = false --ScreenGUI is disabled player.PlayerGui.CollectGUI.Frame.Position = UDim2.new(0, 0, 0, 0) --Frame position is reset player.PlayerGui.CollectGUI.Frame.ItemName.Text = "" --ItemName.Text is reset end end
So you may wonder why that script is not working either.
Well you need a loop which constantly checks the mouse's Target.
local RunService = game:GetService("RunService") local player = game.Players.LocalPlayer local mouse = player:GetMouse() RunService.Stepped:Connect(function(step) --wait(step) --Optional if you want it to coordinate with user's frames if mouse.Target then if mouse.Target:FindFirstChild("BoolValue") then player.PlayerGui.CollectGUI.Enabled = true --ScreenGUI is enabled player.PlayerGui.CollectGUI.Frame.Position = UDim2.new(0, mouse.X, 0, mouse.Y) --Frame follows mouse player.PlayerGui.CollectGUI.Frame.ItemName.Text = mouse.Target.Parent.Name -- ItemName.Text is the part's name else player.PlayerGui.CollectGUI.Enabled = false --ScreenGUI is disabled player.PlayerGui.CollectGUI.Frame.Position = UDim2.new(0, 0, 0, 0) --Frame position is reset player.PlayerGui.CollectGUI.Frame.ItemName.Text = "" --ItemName.Text is reset end end end)
I wish you goodluck on solving your issue if my answer did not help.
just remove the event called PlayerAdded. Local scripts can't seem to use that event. the following code is the fix.
local Players = game:GetService("Players") local UIS = game:GetService("UserInputService") UIS.InputChanged:Connect(function(input) local player = Players.LocalPlayer local mouse = player:GetMouse() if mouse.Target then if mouse.Target:FindFirstChild("BoolValue") then player.PlayerGui.CollectGUI.Enabled = true --ScreenGUI is enabled player.PlayerGui.CollectGUI.Frame.Position = UDim2.new(0, mouse.X+3, 0, mouse.Y+3) --Frame follows mouse player.PlayerGui.CollectGUI.Frame.ItemName.Text = mouse.Target.Parent.Name -- ItemName.Text is the part's name else player.PlayerGui.CollectGUI.Enabled = false --ScreenGUI is disabled player.PlayerGui.CollectGUI.Frame.Position = UDim2.new(0, 0, 0, 0) --Frame position is reset player.PlayerGui.CollectGUI.Frame.ItemName.Text = "" --ItemName.Text is reset end end end)
Since we're inside a player via the local script its unnecessary to call that event for all players on the server. Now if this was a server side script then it would work!.
just incase your wondering on line 1 the:
local Players = game:GetService("Players")
is the same as:
local player = game.Players.LocalPlayer