Ad
Log in to vote
0

Tried to index a function with WaitForChild?

Asked by 7 days ago
Edited 7 days 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 48 — 7d
0
What line does the error occur on? wolftamer894 48 — 7d

2 answers

Log in to vote
0
Answered by
0hsa 174
7 days 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 7 days 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