I tried to script about Cars spawner GUI shop that alot Cities game do, i try to search online like Youtube. but since filtering enabled on, it wont worked. i dont want my game exploited tho... anyone help me please??
For this task, we will specifically use the Remote Events
Remote Events
are Roblox Instances
that allows you to communicate with two different scripts. Some of these actions can only be performed by server
and some can only be done with client.
When creating a game, you need to identify which action is suitable for server and client.
Basically think of it as an another version of Bindable Event
. However, Do Not confuse Remote Event
with Bindable Event
. They are not the same.
Remote Events
are usually placed in ReplicatedStorage
because ReplicatedStorage
can be accessed by both Server
and Client
Script.
To implement Remote Event
in the game
, the following steps are used:
Replicated Storage
Remote Events
or scroll down till you find one. Remote Event
Firstly, you want to make sure you have 2 different scripts. One script is a Server Script
while the other is Client Script
. The Server Script
; we will call it Cloner
, goes to ServerScriptService
. The Client Script
; we will call it EventFirer
, goes to your Graphic User Interface
button.
-- Declaration Section [EventFirer] -- //Game Services local Player = game:GetService("Players").LocalPlayer local PlayerGui = Player:WaitForChild("PlayerGui") local ReplicatedStorage = game:GetService("ReplicatedStorage") -- //Remote Event Location local ModelCloningEvent = ReplicatedStorage:WaitForChild("ModelCloningEvent") -- //Gui Location local ScreenGui = PlayerGui:WaitForChild("ScreenGuiName") local TextButton = ScreenGui:WaitForChild("TextButtonName") -- Processing Section local function FireModelCloningEvent () ModelCloningEvent:FireServer() print("Fired Server") end -- Connecting Section TextButton.MouseButton1Down:Connect(FireModelCloningEvent)
Basically the script above is firing
the Remote Event
when the TextButton
is pressed.
-- Declaration Section -- //Game Services local ReplicatedStorage = game:GetService("ReplicatedStorage") local ServerStorage = game:GetService("ServerStorage") local Workspace = game:GetService("Workspace") -- //Cloning Model Location local Car = ServerStorage:WaitForChild("Car") -- //Remote Event Location local ModelCloningEvent = ReplicatedStorage:WaitForChild("ModelCloningEvent") -- //Variables local NewCar -- Processing Section local function CloneCarToWorkspace () NewCar = Car:Clone() NewCar.Parent = Workspace NewCar:MakeJoints() print("Cloned Car in Workspace") end -- Connecting Section ModelCloningEvent.OnServerEvent:Connect(CloneCarToWorkspace)
The script above is the main code. When the ModelCloningEvent
is fired, the function
will begin to process. The Car
found in ServerStorage
; Note: The Car's location is for this tutorial is in ServerStorage
; is cloned to the Workspace
Please do keep in mind that this is just a basic script. You can do many more cool things with it. However my objective is to guide you, not give you free script.
Hope you learned something from this. Check out more