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

Tried to index a function with WaitForChild?

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)

2 comments

0

What line does the error occur on?

0

What line does the error occur on?

2 answers

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

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

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