Hello Vortex_Vasne
There is no need to stress, someone would help you eventually.
I am here with a rewritten script and I will teach you how it works!
Let's begin!
So firstly, we need to insert a Part into the Workspace. Name this Part, Gem
. Now that we have a Gem, feel free to decorate it however you like. Now insert a regular script inside of this Gem. Open it and you will find a plain, stale and bland line of code saying print("Hello World!")
. Remove this completely and begin to type in the following.
1 | local ws = game:GetService( "Workspace" ) |
2 | local rs = game:GetService( "ReplicatedStorage" ) |
Now as you can see, the code above may look complicated, but trust me, it isn't at all. All we're doing is making the Workspace and ReplicatedStorage a two letter word inside of this script! Make sure you have written this first. Now, duplicate the Gem into how many you want, whether it be 3, 10 or maybe even 40, it's all up to you. To duplicate a part, click it and then press CTRL and D at the same time on your keyboard.
Now that you have created multiple Gems, name the first Gem, Gem1
, the second, Gem2
and keep following the corresponding number until you've reached naming all of your Gems separately. This will help get rid of your teleporting all at once issue.
Now, select all the parts in one batch and press CTRL and G on your keyboard to create a model with the Gems inside. What this will do is allow us to easily sort through all the Gems until we find the one that was touched.
Good job, you have made it this far! Now let's implement another line of code.
1 | local ws = game:GetService( "Workspace" ) |
2 | local rs = game:GetService( "ReplicatedStorage" ) |
3 | local gems = ws:WaitForChild( "Gems" ) |
Now, press CTRL and I on your keyboard, make sure you didn't type a one, but an I. This will open the advanced properties, now what you want to do is type Model, double click model and it should appear in your Workspace, drag that into your ReplicatedStorage and name it Gems2
. Go back to the script and implement one more line of code.
1 | local ws = game:GetService( "Workspace" ) |
2 | local rs = game:GetService( "ReplicatedStorage" ) |
3 | local gems = ws:WaitForChild( "Gems" ) |
4 | local gems 2 = rs:WaitForChild( "Gems2" ) |
Now that we've gotten rid of the boring part, let's get into the actual scripting.
Firstly, create your function and name it TouchingGem, we'll need it to be named TouchingGem as we'll use it further in our code.
1 | local ws = game:GetService( "Workspace" ) |
2 | local rs = game:GetService( "ReplicatedStorage" ) |
3 | local gems = ws:WaitForChild( "Gems" ) |
4 | local gems 2 = rs:WaitForChild( "Gems2" ) |
Now we have a whole area to do whatever we want, in this instance we'll make it so whenever the Gem is touched by a player, it moves to the ReplicatedStorage for some time and comes right back!
Before we run more code, we need to make sure the thing who touches the Gem is an actual player and not another object we don't know. To do this, we need to Find the Humanoid doing the following.
01 | local ws = game:GetService( "Workspace" ) |
02 | local rs = game:GetService( "ReplicatedStorage" ) |
03 | local gems = ws:WaitForChild( "Gems" ) |
04 | local gems 2 = rs:WaitForChild( "Gems2" ) |
06 | function TouchingGem(hit) |
07 | if hit.Parent:FindFirstChild( "Humanoid" ) then |
Make sure you insert hit as a parameter in the function.
Now, we need to teleport or move the Gem!
01 | local ws = game:GetService( "Workspace" ) |
02 | local rs = game:GetService( "ReplicatedStorage" ) |
03 | local gems = ws:WaitForChild( "Gems" ) |
04 | local gems 2 = rs:WaitForChild( "Gems2" ) |
06 | function TouchingGem(hit) |
07 | if hit.Parent:FindFirstChild( "Humanoid" ) then |
08 | gems:FindFirstChild(script.Parent.Name).Parent = gems 2 |
10 | gems 2 :FindFirstChild(script.Parent.Name).Parent = gems |
We're so close I can feel it! All we need to do now is add the finishing touches!
01 | local ws = game:GetService( "Workspace" ) |
02 | local rs = game:GetService( "ReplicatedStorage" ) |
03 | local gems = ws:WaitForChild( "Gems" ) |
04 | local gems 2 = rs:WaitForChild( "Gems2" ) |
06 | function TouchingGem(hit) |
07 | if hit.Parent:FindFirstChild( "Humanoid" ) then |
08 | gems:FindFirstChild(script.Parent.Name).Parent = gems 2 |
10 | gems 2 :FindFirstChild(script.Parent.Name).Parent = gems |
14 | script.Parent.Touched:Connect(TouchingGem) |
There you go, a fully working system! Feel free to paste and this has been a pleasure working with you, have a fantastic day Vortex!
Sincerely, TheOnlySmarts.
If this worked or I helped you learn something today, please Accept the Answer!