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

Tried to index a function with WaitForChild?

Asked by 3 years ago
Edited 3 years ago

when i run the game the error in the title appear

local player = game.Players.GetPlayerFromCharacter
local leaderstats = player:WaitForChild("leaderstats")
local config = script.Parent.Parent.Parent.Frame.ScrollingFrame.Frame.ImageButton.Config

script.Parent.MouseButton1Click:Connect(function()
    if leaderstats.Diamonds.Value >= config.Cost.Value then
        leaderstats.Diamonds.Value = leaderstats.Diamonds.Value - config.Cost.Value
    end

end)
0
What line does the error occur on? wolftamer894 50 — 3y
0
What line does the error occur on? wolftamer894 50 — 3y

2 answers

Log in to vote
0
Answered by
0hsa 193
3 years ago

getplayerfromcaharcter is a function, you'd have to call it:

local player = game.Players:GetPlayerFromCharacter( the player you have )
local leaderstats = player:WaitForChild("leaderstats")
local config = script.Parent.Parent.Parent.Frame.ScrollingFrame.Frame.ImageButton.Config

script.Parent.MouseButton1Click:Connect(function()
    if leaderstats.Diamonds.Value >= config.Cost.Value then
        leaderstats.Diamonds.Value = leaderstats.Diamonds.Value - config.Cost.Value
    end

end)

this error is because players has that same function and you're indexing it instead of calling it so if you were to do: player(someplayer) it would work

and if it's in a localscript just use game:GetService('Players').LocalPlayer

Ad
Log in to vote
0
Answered by 3 years ago
-- you didn't finish getplayerfromcharacter.
-- from looking at this line, local config = script.Parent.Parent.Parent (if the third parent is the screen GUI) you could do

local player = script.Parent (button) .Parent (frame) .Parent (screen gui) .Parent (playergui) .Parent (player) 

Answer this question