Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

It keeps bringing the same thing thats named the same thing how can i fix?

Asked by 4 years ago
Edited 4 years ago

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"

0
Then rename gem to something else greatneil80 2647 — 4y
0
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 Songist 49 — 4y
0
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 Vortex_Vasne 89 — 4y
0
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. TheOnlySmarts 233 — 4y
View all comments (4 more)
0
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. TheOnlySmarts 233 — 4y
0
Okay sweet I have figured out how to make it! TheOnlySmarts 233 — 4y
0
Sorry if i'm late but you might wanna change "script.Parent.ReplicatedStorage" to "game.ReplicatedStorage" or "game:GetService("ReplicatedStorage")" speedyfox66 237 — 4y
0
Speedyfox, that wouldn't work though because there are obviously multiple gems. So it'd grab all of them. TheOnlySmarts 233 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

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") -- 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!

Sincerely, TheOnlySmarts.

If this worked or I helped you learn something today, please Accept the Answer!
Ad

Answer this question