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

[SOLVED] How do make it when I hoverover a Part that has BoolValue UI appears and follows the mouse?

Asked by 4 years ago
Edited 4 years ago

Information:

  • I am not getting any errors
  • I already attempted this, it didn't work.
  • The parent of the script StarterCharacter.StarterPlayerScripts
  • The script is a LocalScript
  • The part is in Workspace.
  • The BoolValue is in the part.
  • There are multiple parts.

Attempt:

01local UIS = game:GetService("UserInputService")
02local player = game.Players.LocalPlayer
03local mouse = player:GetMouse() 
04 
05game.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 = UDim2.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 = UDim2.new(0, 0, 0, 0) --Frame position is reset
15            player.PlayerGui.CollectGUI.Frame.ItemName.Text = "" --ItemName.Text is reset
16        end
17    end
18end)
19end)

2 answers

Log in to vote
1
Answered by
uhi_o 417 Moderation Voter
4 years ago
Edited 4 years ago

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

01local player = game.Players.LocalPlayer
02local mouse = player:GetMouse() 
03 
04 
05if 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 = UDim2.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 = UDim2.new(0, 0, 0, 0) --Frame position is reset
13        player.PlayerGui.CollectGUI.Frame.ItemName.Text = "" --ItemName.Text is reset
14    end
15end

So you may wonder why that script is not working either.

Well you need a loop which constantly checks the mouse's Target.

01local RunService = game:GetService("RunService")
02local player = game.Players.LocalPlayer
03local mouse = player:GetMouse() 
04 
05RunService.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 = UDim2.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 = UDim2.new(0, 0, 0, 0) --Frame position is reset
15            player.PlayerGui.CollectGUI.Frame.ItemName.Text = "" --ItemName.Text is reset
16        end
17    end
18end)

I wish you goodluck on solving your issue if my answer did not help.

1
Hello! I am here to inform you that in this case, RunService.Stepped is more useful then RunService.RenderStepped User#30567 0 — 4y
0
Thanks for the info, I don't really know the difference. I appreciate you telling me that. uhi_o 417 — 4y
Ad
Log in to vote
0
Answered by
TGazza 1336 Moderation Voter
4 years ago

just remove the event called PlayerAdded. Local scripts can't seem to use that event. the following code is the fix.

01local Players = game:GetService("Players")
02 
03local 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 = UDim2.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 = UDim2.new(0, 0, 0, 0) --Frame position is reset
17            player.PlayerGui.CollectGUI.Frame.ItemName.Text = "" --ItemName.Text is reset
18        end
19    end
20end)

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:

1local Players = game:GetService("Players")

is the same as:

1local player = game.Players.LocalPlayer
0
I don't know if this works, but I checked the other answer first that's why you didn't get your answer accepted if it was correct. Dave_Robertson 42 — 4y
0
this answer only updates when you touch the mouse/keyboard, touch device. the other answer is running all the time. Both are valid though and fair dos, uhi_o answered just before mine i think a second before lol. as long as you got it working :). TGazza 1336 — 4y

Answer this question