Information:
Attempt:
01 | local UIS = game:GetService( "UserInputService" ) |
02 | local player = game.Players.LocalPlayer |
03 | local mouse = player:GetMouse() |
04 |
05 | game.Players.PlayerAdded:Connect( function (player) |
06 | UIS.InputChanged:Connect( function (input) |
07 | if mouse.Target then |
08 | if mouse.Target:FindFirstChild( "BoolValue" ) then |
09 | player.PlayerGui.CollectGUI.Enabled = true --ScreenGUI is enabled |
10 | player.PlayerGui.CollectGUI.Frame.Position = UDim 2. new( 0 , mouse.X, 0 , mouse.Y) --Frame follows mouse |
11 | player.PlayerGui.CollectGUI.Frame.ItemName.Text = mouse.Target.Parent.Name -- ItemName.Text is the part's name |
12 | else |
13 | player.PlayerGui.CollectGUI.Enabled = false --ScreenGUI is disabled |
14 | player.PlayerGui.CollectGUI.Frame.Position = UDim 2. new( 0 , 0 , 0 , 0 ) --Frame position is reset |
15 | player.PlayerGui.CollectGUI.Frame.ItemName.Text = "" --ItemName.Text is reset |
16 | end |
17 | end |
18 | end ) |
19 | 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
01 | local player = game.Players.LocalPlayer |
02 | local mouse = player:GetMouse() |
03 |
04 |
05 | if mouse.Target then |
06 | if mouse.Target:FindFirstChild( "BoolValue" ) then |
07 | player.PlayerGui.CollectGUI.Enabled = true --ScreenGUI is enabled |
08 | player.PlayerGui.CollectGUI.Frame.Position = UDim 2. new( 0 , mouse.X, 0 , mouse.Y) --Frame follows mouse |
09 | player.PlayerGui.CollectGUI.Frame.ItemName.Text = mouse.Target.Parent.Name -- ItemName.Text is the part's name |
10 | else |
11 | player.PlayerGui.CollectGUI.Enabled = false --ScreenGUI is disabled |
12 | player.PlayerGui.CollectGUI.Frame.Position = UDim 2. new( 0 , 0 , 0 , 0 ) --Frame position is reset |
13 | player.PlayerGui.CollectGUI.Frame.ItemName.Text = "" --ItemName.Text is reset |
14 | end |
15 | end |
So you may wonder why that script is not working either.
Well you need a loop which constantly checks the mouse's Target.
01 | local RunService = game:GetService( "RunService" ) |
02 | local player = game.Players.LocalPlayer |
03 | local mouse = player:GetMouse() |
04 |
05 | RunService.Stepped:Connect( function (step) |
06 | --wait(step) --Optional if you want it to coordinate with user's frames |
07 | if mouse.Target then |
08 | if mouse.Target:FindFirstChild( "BoolValue" ) then |
09 | player.PlayerGui.CollectGUI.Enabled = true --ScreenGUI is enabled |
10 | player.PlayerGui.CollectGUI.Frame.Position = UDim 2. new( 0 , mouse.X, 0 , mouse.Y) --Frame follows mouse |
11 | player.PlayerGui.CollectGUI.Frame.ItemName.Text = mouse.Target.Parent.Name -- ItemName.Text is the part's name |
12 | else |
13 | player.PlayerGui.CollectGUI.Enabled = false --ScreenGUI is disabled |
14 | player.PlayerGui.CollectGUI.Frame.Position = UDim 2. new( 0 , 0 , 0 , 0 ) --Frame position is reset |
15 | player.PlayerGui.CollectGUI.Frame.ItemName.Text = "" --ItemName.Text is reset |
16 | end |
17 | end |
18 | 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.
01 | local Players = game:GetService( "Players" ) |
02 |
03 | local UIS = game:GetService( "UserInputService" ) |
04 |
05 | UIS.InputChanged:Connect( function (input) |
06 |
07 | local player = Players.LocalPlayer |
08 | local mouse = player:GetMouse() |
09 | if mouse.Target then |
10 | if mouse.Target:FindFirstChild( "BoolValue" ) then |
11 | player.PlayerGui.CollectGUI.Enabled = true --ScreenGUI is enabled |
12 | player.PlayerGui.CollectGUI.Frame.Position = UDim 2. new( 0 , mouse.X+ 3 , 0 , mouse.Y+ 3 ) --Frame follows mouse |
13 | player.PlayerGui.CollectGUI.Frame.ItemName.Text = mouse.Target.Parent.Name -- ItemName.Text is the part's name |
14 | else |
15 | player.PlayerGui.CollectGUI.Enabled = false --ScreenGUI is disabled |
16 | player.PlayerGui.CollectGUI.Frame.Position = UDim 2. new( 0 , 0 , 0 , 0 ) --Frame position is reset |
17 | player.PlayerGui.CollectGUI.Frame.ItemName.Text = "" --ItemName.Text is reset |
18 | end |
19 | end |
20 | 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:
1 | local Players = game:GetService( "Players" ) |
is the same as:
1 | local player = game.Players.LocalPlayer |