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.
local ws = game:GetService("Workspace")
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.
local ws = game:GetService("Workspace")
local rs = game:GetService("ReplicatedStorage")
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.
local ws = game:GetService("Workspace")
local rs = game:GetService("ReplicatedStorage")
local gems = ws:WaitForChild("Gems")
local gems2 = 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.
local ws = game:GetService("Workspace")
local rs = game:GetService("ReplicatedStorage")
local gems = ws:WaitForChild("Gems")
local gems2 = rs:WaitForChild("Gems2")
function TouchingGem()
end
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.
local ws = game:GetService("Workspace")
local rs = game:GetService("ReplicatedStorage")
local gems = ws:WaitForChild("Gems")
local gems2 = rs:WaitForChild("Gems2")
function TouchingGem(hit)
if hit.Parent:FindFirstChild("Humanoid") then
end
end
Make sure you insert hit as a parameter in the function.
Now, we need to teleport or move the Gem!
local ws = game:GetService("Workspace")
local rs = game:GetService("ReplicatedStorage")
local gems = ws:WaitForChild("Gems")
local gems2 = rs:WaitForChild("Gems2")
function TouchingGem(hit)
if hit.Parent:FindFirstChild("Humanoid") then
gems:FindFirstChild(script.Parent.Name).Parent = gems2
wait(60)
gems2:FindFirstChild(script.Parent.Name).Parent = gems
end
end
We're so close I can feel it! All we need to do now is add the finishing touches!
local ws = game:GetService("Workspace")
local rs = game:GetService("ReplicatedStorage")
local gems = ws:WaitForChild("Gems")
local gems2 = rs:WaitForChild("Gems2")
function TouchingGem(hit)
if hit.Parent:FindFirstChild("Humanoid") then
gems:FindFirstChild(script.Parent.Name).Parent = gems2
wait(60)
gems2:FindFirstChild(script.Parent.Name).Parent = gems
end
end
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!
8 comments
Then rename gem to something else
Is the "gem" part you want moved script.Parent or some other part? Is it's script.Parent why not just define the part as script.Parent before the function? before the function
OK I AM SUPPOSED TO BE MAKING A GAME RN BUT I CANT DO THSI FOR SOME REASON I NEED HELP DOING THIS PLZ TEH SCRIPSTS ARE ABOVE
Here, I am testing out how to fix this in my ROBLOX studio, I should reply with an answer soon, if not, I have got no clue.
I am confused, is this script inside of the gem Vortex? I can help you on Discord if you'd like, because this is an easy fix, it's just you need to provide stronger information.
Okay sweet I have figured out how to make it!
Sorry if i'm late but you might wanna change "script.Parent.ReplicatedStorage" to "game.ReplicatedStorage" or "game:GetService("ReplicatedStorage")"
Speedyfox, that wouldn't work though because there are obviously multiple gems. So it'd grab all of them.