How to put this into a remote function script?

Hello,

So i’m trying to use the script from client to server from the developers hub, but I don’t know how I can make it that when a player clicks a button that something gets cloned. I already have it that the model gets cloned but I need to put it in a other script for the remote function. So no exploiter/hacker can give themself cash.

Can someone help me with this please?!

Here’s are both scripts local and normal;

-- LocalScript
 
local ReplicatedStorage = game:GetService("ReplicatedStorage")
 
local createPartRequest = ReplicatedStorage:WaitForChild("CreatePartRequest")
 
local newPart = createPartRequest:InvokeServer()
print("The server created this part for me:", newPart)
 
 
-- ==================================================
 
 
-- Script
 
local ReplicatedStorage = game:GetService("ReplicatedStorage")
 
local createPartRequest = Instance.new("RemoteFunction")
createPartRequest.Parent = ReplicatedStorage
createPartRequest.Name = "CreatePartRequest"
 
local function onCreatePartRequested(player)
	print(player.Name, "wants to create a new part")
	local newPart = Instance.new("Part")
	newPart.Parent = game.Workspace
	return newPart
end
 
createPartRequest.OnServerInvoke = onCreatePartRequested

Btw, where does the local script needs to be in? In the purchase button?

1 Like

When a TextButton or ImageButton is clicked, the .Activated event fires, and from that event, you can make the remote function fire.

Yes, the local script goes into the purchase button.

Local Script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
 
local createPartRequest = ReplicatedStorage:WaitForChild("CreatePartRequest")
 
script.Parent.Activated:Connect(function()
     local newPart = createPartRequest:InvokeServer(game:GetService("Players").LocalPlayer)
     print("The server created this part for me:", newPart)
end

Server Script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
 
local createPartRequest = Instance.new("RemoteFunction")
createPartRequest.Parent = ReplicatedStorage
createPartRequest.Name = "CreatePartRequest"
 
local function onCreatePartRequested(player)
	print(player.Name, "wants to create a new part")
	local newPart = Instance.new("Part")
	newPart.Parent = game.Workspace
	return newPart
end
 
createPartRequest.OnServerInvoke = onCreatePartRequested(player)

So in the local script he is going to call the script in serverscriptservice right? And if the value equals 300 then it will return the cloned model? Or am I totally wrong?