I have this script that put a text label next to the mouse as you move it around, if you hover over a player, it shows their player name next to the mouse and when you don't hover over a player, it shows nothing. This script works in Studio on test mode and the test server feature, but it doesn't work in-game roblox. Any suggestions?
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local debounce = false
local target = nil
local playerFound = false
local playerName = nil
mouse.Move:connect(function()
target = mouse.Target
if not target --[[or not (target.Parent:findFirstChild("Humanoid"))]] then
if player.PlayerGui:findFirstChild("MouseText") then
player.PlayerGui.MouseText.TextLabel.Text = ""
end
else
if not (player.PlayerGui:findFirstChild("MouseText")) then
local mouseGui = Instance.new("ScreenGui",player.PlayerGui)
mouseGui.Name = "MouseText"
local mouseText = Instance.new("TextLabel",mouseGui)
mouseText.Size = UDim2.new(0,10,0,10)
mouseText.BackgroundTransparency = 1
mouseText.TextXAlignment = "Left"
mouseText.TextStrokeTransparency = 0
mouseText.TextColor3 = Color3.new(255,255,255)
end
if player.PlayerGui:findFirstChild("MouseText") then
if target.Parent:IsA("Hat") and target.Parent.Parent:findFirstChild("Humanoid") then
if target.Parent:findFirstChild("Humanoid") then
player.PlayerGui.MouseText.TextLabel.Text = target.Parent.Parent.Name
playerFound = true
playerName = target.Parent.Parent.Name
else
player.PlayerGui.MouseText.TextLabel.Text = ""
playerFound = false
end
else
if target.Parent:findFirstChild("Humanoid") then
player.PlayerGui.MouseText.TextLabel.Text = target.Parent.Name
playerFound = true
playerName = target.Parent.Name
else
player.PlayerGui.MouseText.TextLabel.Text = ""
playerFound = false
end
end
mouse.Button1Down:connect(function()
if playerFound == true then
if not (player.PlayerGui:findFirstChild("PlayerSelectOption")) then
local newOptionGUI = script.Parent.PlayerSelectOption:clone()
newOptionGUI.Main.PlayerName.Value = playerName
newOptionGUI.Main.Script.Disabled = false
newOptionGUI.Parent = player.PlayerGui
newOptionGUI.Main.Visible = true
end
player.PlayerGui.ServeSystem.Serve.Title.Text = "Serving Player: "..playerName
player.PlayerGui.ServeSystem.Serve.PlayerName.Value = playerName
end
end)
player.PlayerGui.MouseText.TextLabel.Position = UDim2.new(0,mouse.X+10,0,mouse.Y-5)
end
end
end)
