Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Need help generating a brick upon a button press?

Asked by
Raeso 5
5 years ago
    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

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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)

0
Aaah, thank you! Raeso 5 — 5y
0
Glad to help! MythicalShade 420 — 5y
Ad

Answer this question