Billboard GUI not cloning onto player head from ImageButton

Hey there, I’m trying to get a Billboard GUI to clone onto the players head after they’ve clicked a ImageButton. I’ve put a screenshot of my code that already works but does it automatically when the player joins instead of when they press the button.

(Code in the image button)
image

(Code that works in ServerScriptService)

Anybody have a fix?

I tried using LocalScript or Script but I couldn’t get it working still.

Hello!

Reading your code, you currently have it so when a button is pressed, every player who joins from then on has the billboard on their head.

To make this work you’ll need to create a RemoteEvent which tells the server to equip the flag on you.

-- LOCALSCRIPT
script.Parent.MouseButton1Click:Connect(function()
    flagRemote:FireServer()
end)
-- SERVER
flagRemote.OnServerEvent(function(Player)
    if Player.Character then
        local flag = game.ServerStorage:WaitForChild("RussiaFlag"):Clone() -- Clone is important to make a copy of the flag
        flag.Parent = Player.Character:WaitForChild("Head")
    end
end)

You just need to define flagRemote somewhere like ReplicatedStorage.

Hopefully this gets you started! I apologize if there are typos, I’m writing this on my phone :smiley:

I would have though that you also need to set the Adornee of the BillboardGui to the same as the Parent property too.

Hey there, I tried what you sent, doesn’t seem to do anything, even when I push the ImageButton it doesn’t try to output anything.

LocalScript:
image

Script in ServerScriptService:
image

Storage:
image

Hey!
It is not working because the connection is missing on the event into the server script.

local player = game:GetService("Players").LocalPlayer
local flagRemote = game:GetService("ReplicatedStorage").flagRemote

script.Parent.MouseButton1Click:Connect(function()
    flagRemote:FireServer()
end)
local flagRemote = game:GetService("ReplicatedStorage").flagRemote

flagRemote.OnServerEvent:Connect(function(player)
    local flag = game.ServerStorage:WaitForChild("RussiaFlag"):Clone()
    flag.Parent = player.Character:WaitForChild("Head")
end)
1 Like

Thank you so much, was really struggling with this.

1 Like

No problem!
Also if you want to do it with multiple different flag, you can do that:

local player = game:GetService("Players").LocalPlayer
local flagRemote = game:GetService("ReplicatedStorage").flagRemote

script.Parent.MouseButton1Click:Connect(function()
    flagRemote:FireServer("RussiaFlag")
end)
local flagRemote = game:GetService("ReplicatedStorage").flagRemote

flagRemote.OnServerEvent:Connect(function(player, flagName)
    local flag = game.ServerStorage:WaitForChild(flagName):Clone()
    flag.Parent = player.Character:WaitForChild("Head")
end)
2 Likes

You shouldn’t need to include player in the call to FireServer. The player that fired the remote event should automatically be included as the first argument when OnServerEvent runs the callback.

Yeah my bad, i forgot about that ^^

Great catch on my Typo :smiley: Should defo not write code on my phone haha

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.