Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Tool's Parent will not change. No output errors?

local function onTouched(hit) --function 
	local sword = game.Lighting.ClassicSword:clone() --clones the tool 
	sword.Parent = hit.Parent:FindFirstChild("Backpack") --puts the tool in backpack
end --end

script.Parent.Touched:Connect(onTouched) --calls the function

i did a breakdown of every line in the script so it's easier to answer. pretty much what it is supposed to do is, when you touch the wedge, it puts a sword in your backpack. but when I test, it doesnt do that. there isnt any output errors. please help ty

1 comment

0

Capitalize the C in Clone()

2 answers

##Explanation

It is better to store your sword in ServerStorage, rather than lighting. Also, the c of Clone() is not capital which is odd, also you need to check if whatever hit the part is a humanoid as well.

##Solution

local ServerStorage = game:GetService("ServerStorage")

local Sword = ServerStorage:WaitForChild("ClassicSword")

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if player then
			Sword:Clone()
			Sword.Parent = player:WaitForChild("Backpack")
		end
	end
end)

2 comments

0

it still doesnt work, there is no output errors

0

Place your sword in ServerStorage

What SilentsReplacement said is correct, I too recommend you store it in the ServerStorage rather than lighting.

Also you were trying to find the Backpack inside the player's character and not the player object.

Follow along my lines, it's pretty self explanatory

Here's my solution:

local function onTouched(hit) --function 
    local tool = game.Lighting:FindFirstChild("ClassicSword")
    if tool then -- check the tool is actually there
	local char = hit.Parent:FindFirstChildWhichIsA("Humanoid") and hit.Parent
        if char then -- check for character
            local player = game.Players:GetPlayerFromCharacter(char)
            if player then -- check there's a player
                local backpack = player:FindFirstChild("Backpack") -- waitforchild is unnecessary
                if backpack then
                    local sword = tool:Clone() --clones the tool 
                    sword.Parent = backpack
                end
            end
        end
    end
end

script.Parent.Touched:Connect(onTouched) --calls the function

1 comment

0

it still doesnt work

This discussion is preserved as it was. New answers, comments, and votes are closed.