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

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

Asked by
ARTEK22 135
8 years ago
Edited 8 years ago

(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)

0
Error? Press f9 in game to look at the error log. User#11440 120 — 8y
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 SH_Helper 61 — 8y

3 answers

Log in to vote
0
Answered by
FiredDusk 1466 Moderation Voter
8 years ago

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)

0
Thanks @FiredDusk ! ARTEK22 135 — 8y
0
Oh nice, it worked I guess! Np. FiredDusk 1466 — 8y
Ad
Log in to vote
0
Answered by 8 years ago
Edited 8 years ago

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)

0
His variables were correct. TheHospitalDev 1134 — 8y
0
but he didn't use them how he should have, some weren't used at all Happywalker 185 — 8y
Log in to vote
0
Answered by 8 years ago
Edited 8 years ago

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)
0
You clone the sword twice. You only need one or the other. TheHospitalDev 1134 — 8y
0
After giving the sword myself, i cant give it myself again. I can do it only once. @WITKOSKI ARTEK22 135 — 8y
0
Mk I fixed it. WITKOSKI 2 — 8y

Answer this question