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

Need help generating a brick upon a button press?

	game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function()
		local player = game.Players.LocalPlayer
		local anvilPart = Instance.new("Part")
		local playerPos = player.Character.Head.Position
		local anvilPos = anvilPart.Position
		anvilPart.CFrame = CFrame.new(playerPos, 10, playerPos)
		game.Players.LocalPlayer.Character.Head:Remove()
	end)

So what I am trying to do is when a button on the screen is clicked, the players head is removed and a brick/ "anvil" falls on the position of where their head was. Issue is, is that while the head ends up being deleted, no part appears to fall on the player in any form. I probably messed up big time lol, but I'd be glad for someone to help me right this wrong.

1 answer

✓ Accepted answer

You didn't mess up big time at all. Just a simple mistake. You created the anvil part, but you never gave it a parent. Simply put the following line of code in your script after you create the anvilPart.

anvilPart.Parent = game.Workspace -- you could change the parent if you wanted to

Also on a separate note, game.Players.LocalPlayer doesn't work in a server script. However, when you use FireServer() it passes the player who used it to the server script. So to get the player simply do

Event.OnServerEvent:Connect(function(player)

2 comments

0

Aaah, thank you!

0

Glad to help!

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