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

How do I give the player a sword inside ServerStorage when they teleport using a TextButton?

I have my ClassicSword put inside ServerStorage. I need it to be put into the players inventory when they press this TextButton. P.S. its also a Local Script.

local Character = game.Players.LocalPlayer.Character--Variable


function leftClick()--Click Function
	print("Teleport!")
	Character.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(0, 0, 335))--Teleports the player!
	--I need my sword giver right here!
end

script.Parent.MouseButton1Click:Connect(leftClick)--Click function



1 answer

✓ Accepted answer

As mentioned in your last post. You cannot make requests for us to make code for you. it's no constructive for the other users, and nobody learns. Yet, I will look past that and aid you either way.

Firstly, you need to move the Tool to ReplicatedStorage, as LocalScripts cannot reference ServerStorage; therefore leaving the Tool inaccessible.

The Tool needs to be duplicated, and moved into the Clients backpack, which is the equivalent to StarterPack in Studio.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Tool = ReplicatedStorage:WaitForChild("Tool"):Clone()
local Player = game:GetService("Players").LocalPlayer

local function onLeftClick()
	local Backpack = Player:FindFirstChild("Backpack")
	if (Backpack) then
		Tool.Parent = Backpack
	end
end

script.Parent.MouseButton1Click:Connect(onLeftClick)

You will have to integrate this code by yourself, as I said before, I cannot give you a full answer, if you haven’t tried.

2 comments

0

I did try but i deleted it and then i released this post so sorru about that

0

That's fine, it's just Community Guidelines, we have to follow a set of rules.

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