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

Items cannot be put away when cloned back?

Asked by 8 years ago

Help! When the play clicks x for the second time and the items are brought in they cannot be deselected when selected causing them all to stack onto each other.

wait(1)
print("Loaded")
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local character = Player.Character
local Tools = Player.Backpack
local startgear = Player.StarterGear


function makegearstart()
    for i,v in pairs(Tools:GetChildren()) do 
        v:clone().Parent = startgear
    end
end
makegearstart()

-------------------------------------------
function speed(speed)
    character.Humanoid.WalkSpeed = speed -- speed function
end


function holdingtool()
    for _, child in pairs(character:GetChildren()) do
    if child.ClassName == "Tool" then
     child:remove()
    end
end 
end

function givebacktool()
    for i,v in pairs(startgear:GetChildren()) do 
        v:clone().Parent = Tools
    end
end




Mouse.KeyDown:connect(function(Key) -- main thing
if Key == "x" then 
    if character.Humanoid.WalkSpeed > 0 then
        speed(0)
        Tools:Remove()
        holdingtool()
    else
        speed(16)
        givebacktool()
    end

end
end)

Do you know how to fix this? Thanks.

0
Give a description of your script too so that we know what your trying to do Volodymyr2004 293 — 8y
1
On line 44 --Tools:ClearAllChildren() --You have defined a path to the Backpack, which to my knowledge can't be removed so easily. This will remove everything in it. Edenojack 171 — 8y

1 answer

Log in to vote
1
Answered by
DevSean 270 Moderation Voter
8 years ago

Edit: He completely changed the question...

ServerStorage can only be accessed with server scripts.

You should use ReplicatedStorage instead as this can be accessed by clients and the server.

The reason this works in Studio is because there isn't a server, therefore the ServerStorage is located on the client instead.

For example instead of:

local Animation = game.ServerStorage.Animation

You should use:

local Animation = game:GetService("ReplicatedStorage").Animation

Also make sure you move the animation into the ReplicatedStorage

Ad

Answer this question