Cube spawning in by pressing "C"

Is a server script just a regular script?

Oh i never saw so did it not work for him.

It does but they dont understand where to put the scripts.

yes the server script is a regular

I did everything and it doesn’t work? Was I supposed to add anything?

This is what I did:

Local script:

local UIS = game:GetService("UserInputService")
local Event = game.ReplicatedStorage.RemoteEvent

UIS.InputBegan:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.C then
		Event:FireServer()
	end
end)

Server Script:

local Event = game.ReplicatedStorage.RemoteEvent

Event.OnServerEvent:Connect(function(Player)
	local Part = Instance.new("Part")
	Part.Size = Vector3.new(2, 2, 2)
	Part.Parent = game.Workspace
end)

What my explorer look like:
image

1 Like

If this does not work it is probably not working just for him.

Everything works fine for me so you most be doing everything wrong. Here is the place un-copy locked. C input for brick - Roblox

Generally, it’s good practice to put gui/gui scripts in starter gui and puit other local stuff in player/character scripts.

Thank you! It does work! I marked as solution!

1 Like

BRUHHHHHHHHHHHHHHHHHHHHHH that is unfair

For the client
local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.C then
		local Part = Instance.new("Part")
		-- Do another stuff here
	end
end)
For the server (all the clients)

Put a RemoteEvent within the ReplicatedStorage:

spawncube

Local Script:

local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local spawnCube = ReplicatedStorage:WaitForChild("SpawnCube")

UserInputService.InputBegan:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.C then
		spawnCube:FireServer(--[[You can put more parameters as well]])
	end
end)

Server Script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local spawnCube = ReplicatedStorage:WaitForChild("SpawnCube")

spawnCube.OnServerEvent:Connect(function(--[[You can connect more parameters as well]])
	local Part = Instance.new("Part")
	-- Do another stuff here
end)

I recommend you to put Scripts within the ServerScriptService and LocalScripts within the StarterPlayerScripts which is within the StarterPlayer. Example:

script localscript

I would mark yours as a solution also if I could!

Mine should be solution since he dident come up with that I did.

1 Like

As mine was to be first and was correct.

Ok ill mark yours then. Ill do it in a second.

It works, but it is damm ugly. First of all, InputBegan is fired with any type of input beginning, including mouse click, game pad button, etc. Therefore, input.KeyCode is not guaranteed to exist. You should first check if the UserInputType == Enum.UserInputType.Keyboard.

You have a point. Sorry I didn’t mark yours first.

Its ok, I just dident think it was fair that I had it right but another person took my answer and got the solution.

1 Like

To change the offset, change the arguments given to CFrame.new().

Part.CFrame = player.Character.HumanoidRootPart.CFrame*CFrame.new(0, 0, -5)