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.
-- 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
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)
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)
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.