local plumbob = script.Parent for _, player in pairs(game.Players:GetPlayers()) do local character = player.Character if character then local head = character:FindFirstChild("Head") if head then plumbob.Position = head.Position + Vector3.new (0, 2, 0) wait(.1) end end end
I'm guessing that you want this "plumbob" (I assume you are referring to the thing from The Sims) above each player, all the time. The algorithm you need (in English) is this:
--[[ Whenever a player joins the game: Make a plumb bob for them Do the following until they've left the game: Reposition their plumb bob over their head (if they have one) wait() (At this point, the player has left the game.) Destroy the cloned plumb bob ]]
You have to tell the script not only what to do, but when to do it (your first problem). Methods for that include using loops (ex "while true do") and events. The "whenever a player joins the game" is an event; the "do the following until they've left the game" is a loop with a condition (it could also be a loop with an event). ex:
game.Players.PlayerAdded:connect(Act1) --Act1 will be called every time a player is added while true do Act2() wait() end --Act2 will be called about 30 times per second (based on how quickly 'wait()' returns)
So, based on the English aglorithm I outlined above, The script should be in the workspace or ServerScriptService. Assuming you can put the plumb bob as a model in ServerStorage named "PlumbBob", the lua might be:
local plumbobOriginal = game.ServerStorage.Plumbob game.Players.PlayerAdded:connect(function(player) --Every time a player is added, do the following for that player --Make a plumb bob for them local plumbob = plumbobOriginal:Clone() plumbob.Parent = workspace local head --Continue to reposition the plumbob until they leave while player.Parent ~= game.Players do --when player.Parent is not game.Players, the player has left the game --Reposition their plumb bob over their head (if they have one) head = player.Character and player.Character:FindFirstChild("Head") if head then plumbob.Position = head.Position + Vector3.new(0, 2, 0) end wait() end --Player has left plumbob:Destroy() end
Now, a better solution would be to weld the plumbob to the player's head (and you can do this while leaving the 2 studs space above the head) - you would have to run that code every time the player got a new head (ex by respawning), but you wouldn't need the while
loop, making it a much superior solution. I'm not very good with welds, but you could look it up yourself and experiment if you want.
Hey macabe55101,
local plumbob = script.Parent:FindFirstChild([plumbob's name in quotation marks])
After that, you want to create a new plumbob by cloning this one inside the Generic for loop. This is how you would do that:
for _, player in next, game:GetService("Players"):GetPlayers() do local new_plumbob = plumbob:Clone() end
for _, player in next, game:GetService("Players"):GetPlayers() do local new_plumbob = plumbob:Clone() local character = player.Character coroutine.wrap(function() while wait() do local head = character:FindFirstChild("Head") new_plumbob.Position = head.Position + Vector3.new(0, 2, 0) end end) end
~~ KingLoneCat