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

Part not spawning in your location after you press P?


game:GetService("UserInputService").InputBegan:Connect(function(input)
	if input.KeyCode.Name == "P" and game.Players.LocalPlayer.Character then
		local Players = game:GetService("Players")
		Players.PlayerAdded:Connect(function(player)
			player.CharacterAdded:Connect(function(character)
				local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
				while humanoidRootPart do
					local Part = Instance.new("Part")
					Part.Parent = workspace
					Part.Material = Enum.Material.Glacier
					Part.Position = humanoidRootPart.Position
				end
			end)
		end)
	end


end)

When I press P, it won't spawn a part in the players location.

1 answer

I would recommend firing the event in a local script and putting what you want to happen in a server script reciving the event

So

LocalScript:

game:GetService("UserInputService").InputBegan:Connect(function(input)
	if input.KeyCode.Name == "P" and game.Players.LocalPlayer.Character then
game.ReplicatedStorage.*EventName*:FireServer() --Fires event from local script to server script
end)

ServerScript:

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr) --Reciving the event after fired
	local char = game.Workspace:FindFirstChild(plr.Name) --Finds the player in the workspace
	local humanoidRootPart = char:FindFirstChild("HumanoidRootPart") --Finds the RootPart in the character
	local Part = Instance.new("Part") --Creates new part
	Part.Parent = workspace --Info For parts
	Part.Material = Enum.Material.Glacier
	Part.Position = humanoidRootPart.Position
end)

Learn more about remote events here

2 comments

0

RemoteEvents are pretty cool! They have a lot of different uses.

0

Yea!

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