I'm having trouble with teleporting a part to a local player

  1. What do you want to achieve? Keep it simple and clear!
    I am making a bomberman type game and I’m trying to make a bomb appear at the player’s location when E is pressed

  2. What is the issue? Include screenshots / videos if possible!
    It doesn’t work, despite everything I’ve done. I do it through remote events. I’m fairly new to scripting

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I did, but I found nothing that helped

Just in case, here’s the code
LocalScript:

local BombPlaceEvent = ReplicatedStorage:WaitForChild("BombPlaceEvent")
local UserInputService = game:GetService("UserInputService")
local ActionKey = Enum.KeyCode.E

local keysPressed = UserInputService:GetKeysPressed()
for _, key in ipairs(keysPressed) do
	if (key.KeyCode == ActionKey) then
		BombPlaceEvent:FireServer()
	end
end

ServerScript:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local BombPlaceEvent = ReplicatedStorage.BombPlaceEvent
local bombRS = ReplicatedStorage.Bomb


BombPlaceEvent.OnServerEvent:Connect(function(player)
	local bomb = bombRS:Clone()
	bomb.Parent = game.Workspace
	bomb.Position = player.Character.HumanoidRootPart.CFrame
end)

Any help is appreciated!

1 Like

In the server script, you didn’t position the bomb correctly.
Here’s the code rewrited hopefully it’s fixed

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local BombPlaceEvent = ReplicatedStorage.BombPlaceEvent
local bombRS = ReplicatedStorage.Bomb


BombPlaceEvent.OnServerEvent:Connect(function(player)
	local bomb = bombRS:Clone()
	bomb.Parent = game.Workspace
	bomb.CFrame = CFrame.new(player.Character.HumanoidRootPart.position)
end)
1 Like

Unfortunately it doesn’t work…

Anything in the output? 'char limit"

1 Like

No, nothing in the output either

Hmm, lemme read the codes again, and i’ll come up with something

1 Like
local BombPlaceEvent = ReplicatedStorage:WaitForChild("BombPlaceEvent")
local UserInputService = game:GetService("UserInputService")
local ActionKey = Enum.KeyCode.E

UserInputService.InputBegan:connect(function(input)
	if input.UserInputType == ActionKey then
		BombPlaceEvent:FireServer()
    end
end

replace this code with the one you got in the local script.
and replace the other code i gave you in the serverscript.

1 Like

I would suggest using PivotTo and GetPivot instead of manually setting the CFrame because it is more efficient in my opinion.

1 Like

What’s that may i ask? I never heard of that lol.

2 Likes

You can move a part to the CFrame of a part (usually a model) by getting the pivot. Exampl:

local part = Instance.new(“Part”)

part.Parent = game.Workspace

part:PivotTo(game.Workspace:FindFirstChild(“playername”):GetPivot())
2 Likes

Oh ok, thank you for the information man! You learn something everyday they say huh.

2 Likes

Here’s the api reference
https://developer.roblox.com/en-us/api-reference/function/PVInstance/PivotTo

2 Likes

Still doesn’t work, I replaced both scripts with what you sent

Hmmmmmm, confusing as hell. Anything in the output??

1 Like

No, nothing. Also tried using the pivot thing Wood just sent, but that doesn’t work either

Try putting prints in the codes… And tell me if they do get printed.

1 Like
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local BombPlaceEvent = ReplicatedStorage.BombPlaceEvent
local bombRS = ReplicatedStorage.Bomb


BombPlaceEvent.OnServerEvent:Connect(function(player)
	local bomb = bombRS:Clone()
	bomb.Parent = game.Workspace
   bomb:PivotTo(player.Character:GetPivot))
end)
1 Like

you forgot to continue the code, might wanna edit it now.

2 Likes

it cut off lol (I’m on mobile, it sucks :frowning: )

2 Likes

Oh alright, yeah ik mobile devforum is bad

2 Likes