So i need help with moving a brick named "Gem" but it brings everything else named gem with it how can i fix it? i am trying to move it to replicated storage
function touch() game.Workspace.Gem = game.ReplicatedStorage wait(60) game.ReplicatedStorage.Gem = game.Workspace.Gem end script.Parent.Touched:Connect(touch)
People i cant find it out pls help me the new script i just made is here:
function touch(hit) script.Parent.Workspace = script.Parent.ReplicatedStorage wait(60) script.Parent.ReplicatedStorage = script.Parent.Workspace end script.Parent.Touched:Connect(touch)
and it keeps saying "ReplicatedStorage is not a valid member of MeshPart"
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") -- gets the Workspace local rs = game:GetService("ReplicatedStorage") -- gets the 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") -- waits for Gems(a model) to fully load in
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") -- waits for Gems2(a model) to fully load in
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() -- naming the function 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 -- if has humanoid then etc etc 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 -- moves into gems2 if valid wait(60) gems2:FindFirstChild(script.Parent.Name).Parent = gems -- moves into gems if valid 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!