I've been working on a script to pickup and drop items, I used a local script to get what button a player presses, but unfortunately I can't do things such as cloning from a local script, I want to be able to fire a script when the local script gets a button press, from what I've researched there may be a way to do this with bindable events? I don't understand any of it though. How would I go about doing this?
You can use remote events:
Create a remote event in the replicated storage and name it cloneItem
In a local script:
local ReplicatedStorage = game:GetService("ReplicatedStorage") --keypress event that runs when a player presses a button: game:GetService("UserInputService").InputBegan:Connect(function(button, gameProcessed) -- if the player is typing into chat, clicking the leaderboard, or is in the game settings, then don't process the input instead, exit out of this function. if gameProcessed then return end -- when the player presses f, I am telling the server that I want to run whatever code is connected to the cloneItem event on the server. -- in this example I am passing a string containing the word car. --by passing "Car" as a parameter I am telling my server scripts that I want to clone an item named car. -- see the server script below for more information if input.KeyCode == Enum.KeyCode.F then replicatedStorage.cloneItem:FireServer("Car") end end)
ServerScript:
local ServerStorage = game:GetService("ServerStorage") --this code runs when the player calls the cloneItem:FireServer() --itemName is the name of the model that we want to clone into the game --in the local script above I told the server that I wanted to spawn a car. game:GetService("ReplicatedStorage").cloneItem.OnServerEvent:Connect(function(playerWhoFiredEvent, itemName) print(playerWhoFiredEvent, itemName) --look for the item to clone in the replicated storage local model = ServerStorage:FindFirstChild(itemName) --if we found the model, clone it into the workspace: if model then local clone = model:Clone() clone.Parent = workspace else warn("Game couldn't clone " .. itemName .. " since it was not found in the server storage") end end)