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

How to make a tool go to players backpack when touched then disappears and re-apperes?[Solved]

Asked by 6 years ago
Edited 6 years ago

so I am trying to make an egg that when the player clicks it or touches it (whatever works easier) they get the egg in there backpack and the after 5 minutes the egg re-appears at the spot. Any way to make this work is welcome but I assume I could use a script that clones to backpack and makes Transparency = 1 and CanCollide = false and then wait(300) seconds and "Re-Appears" or becomes seen and able to collide. I have had difficulties trying multiple methods and would like someone with coding knowledge for help. Any help is greatly appreciated.

function onTouched(hit)
    local pos = script.Parent.Position
     if script.Parent.CanCollide == true and hit.Parent:FindFirstChild("Humanoid") and game.Players:FindFirstChild(hit.Parent.Name) then
    script.Parent.Transparency = 1
    script.Parent.CanCollide = false
    local plr = game.Players:FindFirstChild(hit.Parent.Name)
    local place = plr.Backpack
    local clone = script.Parent:Clone()
    clone.Parent = place
    wait(300)
    script.Parent.Transparency = 0
    script.Parent.CanCollide = true
    end
end
script.Parent.Touched:connect(onTouched)

This is one script that seems like it should work but didnt. Feel free to use a completely different way. All I need is an egg that can be collected and re-appears after 5 minutes.

0
If you clone a script's parent, the script will be cloned as well, thus repeating the process.! User#19524 175 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago
function onTouched(hit)
local Pos = script.Parent.Position
local Tool = Instance.new("Tool")
Tool.Name = "Egg"
 if script.Parent.CanCollide == true and hit.Parent:FindFirstChild("Humanoid") then
local plr = game.Players[hit.Parent.Name]
Tool.Parent = plr.Backpack
script.Parent.CanCollide = false
script.Parent.Transparency = 1
wait(60 * 5)
script.Parent.Transparency = 0
script.Parent.CanCollide = true
end
end
script.Parent.Touched:connect(onTouched)
0
should i change anything to WhiteEgg (my tool name). It did nothing when i tried it but when i manually played it through play script it gave me the same error- Tool.Parent = plr.:15: attempt to index global 'script' (a nil value)- JakeDaBeAat 13 — 6y
0
this always happens where nothing occurs in game in the output and when i manually play it i get ...'script' (a nil value) what does it mean JakeDaBeAat 13 — 6y
0
I solved it by using a Tool spawner model which spwns tools afon a block. I made its transparency 1 and out it under the egg and thats how new eggs will spawn thanks though. JakeDaBeAat 13 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

I solved it by using a Tool spawner model which spawns tools on a block. I made its transparency 1 and out it under the egg and thats how new eggs will spawn thanks though.

Answer this question