I'm really new to scripting, So this is probably gonna make people cringe.
What I've been doing: I've been trying to make a script that involves remote events.
What's the goal?: I'm trying to make it so that a brick (Or a piece of Toast, In my case) That spawns on the player when the E keybind is pressed.
What's the issue?: As you know, You need a local script to use a keybind, But I would like it so that everyone can see the brick (Or Toast).
What are my scripts so far?: Script A (LocalScript):
local object = game.Workspace.ToasT local clonedObject = object:Clone() local repStorage = game.GetService("ReplicatedStorage") local remote = repStorage:WaitForChild("Remote") local Key = 'E' game:GetService("UserInputService").InputEnded:connect(function(input,IsTyping) if IsTyping then return end if input.KeyCode == Enum.KeyCode[Key] then remote:FireServer() wait(1) end end)
Script B (Normal Script)
local object = game.Workspace.ToasT local Position = game.StarterPlayer.StarterCharacter.Head.Toaster.Position local ClonedObject = object:Clone() local repStorage = game.GetService("ReplicatedStorage") local remote = repStorage:WaitForChild("Remote") remote.OnServerEvent:Connect(function(player) ClonedObject.Position = Vector3.new(Position) end)
Please help.
First, you cant call the player by "local player" when you are in server script, you have to use other methods, and when you clone something it exists only in memory, so you need to define its parent. You are just missing this:
ClonedObject.Parent = Workspace
Else, i can give you some tips in the code you wrote: you dont need to create the clone in local too (unless you want no lag feel on that action). Dont use a variable for Key sinse you will call it once or twice only. I would do it like this:
local object = game.Workspace.ToasT local remote = game.ReplicatedStorage:WaitForChild("Remote") game:GetService("UserInputService").InputEnded:connect(function(input,IsTyping) if IsTyping then return nil end if input.KeyCode == Enum.KeyCode.E then remote:FireServer("ActionName") end end)
Server script:
local object = game.Workspace.ToasT local ClonedObject = object:Clone() local remote = game.ReplicatedStorage:WaitForChild("Remote") remote.OnServerEvent:Connect(function(player, request) if request == "ActionName" then -- with this you can use this same remote to do other things later without having to create lots of remote events. ClonedObject.Position = Vector3.new(player.Character.Head.Toaster.Position) end end)