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

How do i make a script that gives player a sword when they touch a part?

function onTouch(fire1) local Toucher = fire1.Parent:FindFirstChild("Humanoid") --The toucher local Backpack = game.Players.LocalPlayer.Backpack

if Toucher ~= nil then Toucher.Backpack = Backpack.new("woodensword")

     end

end script.Parent.Touched:connect(onTouch) --

1 comment

0

oh and btw the sword name is "woodensword"

1 answer

"Backpack.new" isn't a thing. What you need to do is set a clone of the wooden sword's parent into the player's backpack.

local backpack = game.Players.LocalPlayer.Backpack

function onTouch(hit)
	if hit ~= nil then
		game.ReplicatedStorage:FindFirstChild("woodensword"):Clone().Parent = backpack

	end
end

Now I don't know where you have the sword stored so change "game.ReplicatedStorage" into the where the sword is

3 comments

0

they underlined blue on my backpack

0

why is that?

0

A script can not acces the local player. You need to define player by hit. If this script was meant to in a local script it still wouldn't work because local scripts do not run in the workspace. In studio that might work with a local script but not in the actual game.

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