Does anyone know how to make it so that when you press “C” a cube spawns in? Can you also tell me where to put the script!
Try putting this in a local script in StarterPlayerScripts:
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.C then
local Part = Instance.new("Part")
Part.Size = Vector3.new(2, 2, 2)
Part.Parent = game.Workspace
end
end)
Note: Only the player who presses C can see the cubes.
Is that all? Nothing seems to be spawning in.
Did you make it a LocalScript and put it inside StarterPlayerScripts? It works for me.
You cant use it in starter player, do “StarterGui”. I would also suggest to use remote events so it will show on server for all players to see.
Why StarterGui? The script should work fine in StarterPlayerScripts, and StarterGui is meant for loading Guis when a player respawns (it’s literally in the name)
Sorry, but by any chance do you know what the remote event script would be?
Your right but not fully. starter gui isn’t just for “gui” specifically. Its best to have it in there so its not lost. As well as since its button input it makes sense but where ever is fine. Its my preference.
Local Script:
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(key, typing)
if typing then return end --// Make sure player isnt typing in chat
if key.KeyCode == Enum.KeyCode.C then
script.RemoteEvent:FireServer() --// Where ever its located
end
end)
Server Script:
script.Parent.RemoteEvent.OnServerEvent:Connect(function(player) --// Again where the remote event is located
local Part = Instance.new("Part")
Part.Size = Vector3.new(2, 2, 2)
Part.Parent = game.Workspace
end)
Added the “Typing” variable so you cant call it in chat.
Lol, sorry I made mistakes kinda rushing this but hope this helps
I added the typing so you cant call it in the chat.
Wouldn’t it be OnClientEvent
instead of OnServerEvent
? You’re calling it from a localscript, including you said :FireServer()
Mistake me if I’m wrong, because I might not know loads about RemoteEvents.
You are wrong. Sorry but its true.
Thats if the server fired to the client
I’m pretty sure you need to put player
in the :FireServer()
quotations.
no, the local script is already passing in the player, it automatically does
I’m stuck, where would I put either of those?
The server script in side the local script, and the remote event in the local script. If that doesent work put the server script in ServerScriptService and the Remote Event in Replicated Storage
And like I said if you get stuck go to this link and it gives everything about Remote Events: Bindable Events and Functions | Roblox Creator Documentation
i think it is
Put this in local script in starter player create a remote event and name it Cuberspawner
local uis = game:GetService("UserInputService") local event = game:GetService("ReplicatedStorage"):WaitForChild("CubeSpawner") uis.InputBegan:Connect(function(input, gpe) if (input.KeyCode == Enum.KeyCode.C and not gpe) then event:FireServer() end end)
Server script in server script service
local event = game:GetService("ReplicatedStorage").PlayerReset event.OnServerEvent:Connect(function(player) Local Cube = instance.new("Part", game.Workspace) Cube.Size = Vector3.new(3,3,3) end)
This is the same thing I have posted