Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

how do i make a gui appear to my head then when i touch another player, it moves to his head?

so, what i'm trying to do is make a fun lil tag game but i can't figure out how to make a gui that says (it) over their head and when u touch another player it moves to their head, for better understanding

you got a (it) text over your head, i see a player, ima go over and tag him.. i tag him, the text goes from my head to his head.

5 comments

0

Do you need help with making the gui or the script that gives the gui to another player? or both

0

wouldn't the gui go into lighting or something? but the scripting part.

0

For the script, when the player with the gui touches another player (use .Touched), change the gui's adornee to the other player's head.

0

Use a BillboardGui and parent it to the player's character.

0

so like script.Parent = game.Player.LocalPlayer.Character.Head?

1 answer

Assuming the gui is in a player's character-

local Players = game:GetService("Players")
local Gui = script.Parent
local GuiOwner = Gui.Parent

local Torso = GuiOwner.Torso

wait(.5) -- Waits half a second so that the person can't tag back instantly.

Torso.Touched:Connect(function(hit) -- Happens when the torso gets touched.
	if hit.Parent:FindFirstChild("Humanoid") then -- Checks if what the player touched has a humanoid.
		if Players:FindFirstChild(hit.Parent.Name) then -- Checks if it's a player.
			local NewGui = Gui:Clone() -- Clones the tag.
			NewGui.Parent = hit.Parent -- Parents the new tag to the touched player.
			NewGui.Adornee = hit.Parent.Head -- Puts the tag above the touched player's head.
			Gui:Destroy() -- Destroys the tag above the old player.
		end
	end
end)

when i join game, the gui doesn't appear over my head, trying to get it where who ever joins game first is it lol.

local rs = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Tagger = false
local Gui = rs:WaitForChild("Gui") -- Or where ever you have the gui

Players.PlayerAdded:Connect(function(plr)
	if Tagger == false then
		Tagger = true -- So it only happens for the first player
		repeat
			wait()
		until plr.Character.Head -- Waits until the player's character is spawned and the head is found.
		Gui.Parent = plr.Character
		Gui.Adornee = plr.Character.Head
	end
end)

Haven't tested this out but it should work.

11 comments

0

when i join game, the gui doesn't appear over my head, trying to get it where who ever joins game first is it lol.

0

Edited my answer.

0

line 11 has an error, ServerScriptService.Script:14: attempt to index field 'Character' (a nil value)

0

Okay, try changing it to just plr.Character.

0

Torso is not a valid member of DataModel (assuming its from the top script) another error

0

Did the player die? Are you using R15 or R6?

0

using r15, should i switch to r6?

0

still gives me the error when i test the game. and no, the player didn't die, it just randomly showed up

0

?

0

If you're using R15, change Torso to UpperTorso or LowerTorso. If that doesn't fix it then I'm not sure.

0

alr, i'll see if anyone knows about the error. thanks for the help.

This discussion is preserved as it was. New answers, comments, and votes are closed.