Hi I am making a game which needs a minimap. But it is not working because roblox developers console is saying Head is not a valid member of model. The script for the minimap works fine in Roblox Studio but it doesn't work in playmode. The error is in line 7.
local maptransparency = .1 -- set to a number between 1 and 0 Controls how transparent the map looks
local mapsize = 200 -- the size in pixels of your minimap
local lagfactor = 10 -- I recommend 4 --- set this from 1-10, with 1 being the most detailed and the most laggy, and ten being the worst detail but least laggy (it can be set to more than ten, but I don't advise it)
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local head = char.Head
local todestroy = {}
script.Parent.speck.Size = UDim2.new(0,lagfactor,0,lagfactor)
script.Parent.Size = UDim2.new(0,mapsize,0,mapsize)
script.Parent.you.Position = UDim2.new(0, (mapsize/2 - 5), 0, (mapsize/2 -5))
function Color(p)
return Color3.new( (p.BrickColor.r),(p.BrickColor.g),(p.BrickColor.b))
end
function visible()
for _, thing in pairs (script.Parent:GetChildren()) do
if thing.ClassName ~= "LocalScript" then
thing.Visible = true
end
end
script.Parent.speck.Visible = false
end
function go()
todestroy = {}
local pos = head.Position + Vector3.new(0,1000,0)
local a
if lagfactor <= 2 then
a = false
end
local x = (-.5 * mapsize)
local z = (-.5 * mapsize)
repeat
x = (-.5 * mapsize)
if a ~= nil then
a = not a
if a == false then
wait()
end
else
wait()
end
repeat
local newpos = pos + Vector3.new(x,0,z)
local ray = Ray.new(newpos, ( (newpos - Vector3.new(0,1000,0) ) - newpos).unit * 3000)
local part,p = workspace:FindPartOnRay(ray)
local oldspeck = script.Parent:FindFirstChild(x .. z)
if oldspeck ~= nil then
todestroy[#todestroy+1] = oldspeck
end
if part ~= nil then
if part:IsA("BasePart") then
local speck = script.Parent.speck:Clone()
speck.BackgroundColor3 = Color(part)
speck.Position = UDim2.new(0,x + ((.5 * mapsize)),0,z + ((.5 * mapsize)))
speck.Name = x .. z
speck.Parent = script.Parent
end
end
x = x + lagfactor
until x >= (.5 * mapsize)
z = z + lagfactor
until z >= (.5 * mapsize)
end
function deleteold()
for i = 1, # todestroy do
todestroy[i]:Destroy()
end
end
while true do
go()
--
visible()
--
deleteold()
end

1 comment
What line does the output say the script is stopping? The output normally tells what line the script stopped after the error message.