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

Why doesn't this script work in a LocalScript?

Asked by 9 years ago

I have a script inside a GUI that gives a player ammo for a bow. Here's the script (it's inside a LocalScript):

function clicked()

local player = game.Players.LocalPlayer
local stats = player:findFirstChild("leaderstats")

player:WaitForDataReady()

    if stats.Points.Value >= 1 then 
        local arrowValue = player:findFirstChild("arrowValue") -- this is the ammo for the bow
        local longbow = player.Backpack:findFirstChild("Long Bow")
        local longbow2 = game.Workspace:findFirstChild(player.Name):findFirstChild("Long Bow") 
        if longbowz then
            arrowValue.Value = arrowValue.Value + 1
            stats.Points.Value = stats.Points.Value - 1
        elseif longbowz2 then
            arrowValue.Value = arrowValue.Value + 1
            stats.Points.Value = stats.Points.Value - 1
        end
    end
end

script.Parent.MouseButton1Down:connect(clicked)

When put into a normal script and the variable for the player (line 4) is changed to script.Parent.Parent.Parent.Parent.Parent (the player), the script works fine. But, when the script is put into a LocalScript and line 4 is changed to player = game.Players.LocalPlayer, the script doesn't work. The script is a descendant of PlayerGui, so why doesn't it work?

1 answer

Log in to vote
0
Answered by
DataStore 530 Moderation Voter
9 years ago

You cannot use WaitForDataReady (or use any other data persistence related methods) from a client-side script, therefore line six is your problem.

0
Ah, okay. whyOmustOitObeOme 7 — 9y
Ad

Answer this question