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

I get a sword in studio by clicking a button but in ROBLOX not?

(Please, don't link me the blog threat, i have read it and it didn't help me)

So i have a script which gives me a sword when i click the button (it's a LocalScript) and it works only in studio, why?

local swordclone = script.Parent.LinkedSword:Clone()
local player = game.Players.LocalPlayer
local button = script.Parent
function clicked()
	script.Parent.LinkedSword:Clone()
	swordclone.Parent = player.Backpack
end


script.Parent.MouseButton1Down:connect(clicked)

2 comments

0

Error? Press f9 in game to look at the error log.

0

At line 5, you never gave a destination to the sword clone. Basiclly, that sword clone is a lost part in the middle on nowhere

3 answers

✓ Accepted answer

I had to hurry so sorry for not explaining, I hope it works.

repeat wait() until game.Players.LocalPlayer.Character --Be on the safe side

local Sword = script.Parent:WaitForChild("LinkedSword")
local player = game.Players.LocalPlayer
local button = script.Parent

script.Parent.MouseButton1Click:connect(function()
	if player.Character:FindFirstChild('LinkedSword') == nil then
		Sword:Clone().Parent = player.Backpack
	end
end)

2 comments

0

Thanks @FiredDusk !

0

Oh nice, it worked I guess! Np.

You aren't really using your variables how you should

local sword = script.Parent.LinkedSword
local player = game.Players.LocalPlayer
local button = script.Parent

function clicked()
    sword:Clone().Parent = player.Backpack
end

button.MouseButton1Down:connect(clicked)

2 comments

0

His variables were correct.

0

but he didn't use them how he should have, some weren't used at all

This is simple you forgot that for the server it takes longer to load the sword and the local script runs faster so it can't find the sword cusess it's not there so the script breaks the start. try this

local Sword = script.Parent:WaitForChild("LinkedSword")
local player = game.Players.LocalPlayer
local button = script.Parent
script.Parent.MouseButton1Click:connect(function()
script.Parent.LinkedSword:Clone().Parent = player.Backpack
end)

3 comments

0

You clone the sword twice. You only need one or the other.

0

After giving the sword myself, i cant give it myself again. I can do it only once. @WITKOSKI

0

Mk I fixed it.

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