I have a game and I want a selection box to appear when the mouse hovers over the player. This is the script I have so far:
local player = game.Players.LocalPlayer local mouse = player:GetMouse() mouse.Move:Connect(function(target) if mouse.Target == nil then wait() elseif mouse.Target.Parent.Name == player.Name then print("Cannot select self") elseif mouse.Target:IsA("MeshPart") or mouse.Target.Name == "Head" then print("Found "..mouse.Target.Parent) local box = game:GetService("ReplicatedStorage").Objects.Select:Clone() for i,v in next, mouse.Target.Parent:GetChildren() do if v:IsA("MeshPart") or v.Name == "Head" then box.Parent = v end end end end)
It errors and says 10: attempt to concatenate field 'Parent' (a userdata value)
Set the SelectionBox's Adornee to the player's Character Model. Also, you can shorten the detection of the player by using the:
Try this: (LocalScript in StarterCharacter)
local player = game.Players.LocalPlayer local mouse = player:GetMouse() local sb = Instance.new("SelectionBox",script.Parent) mouse.Move:Connect(function() local target = mouse.Target if target then local tPlayer = game.Players:GetPlayerFromCharacter(target.Parent) sb.Adornee = tPlayer and tPlayer.Character or nil -- You can test true / false when setting values: -- if 'tPlayer' exists, then set to 'tPlayer.Character' or set to Nil end end)
You cannot concatenate objects, you have to index the Name
property.
print("Found "..mouse.Target.Parent.Name) --Line 10