#Pls Help

1 messages · Page 1 of 1 (latest)

sharp junco
#

I wrote this function in a framework and it runs on the client when the player runs but doesnt work


CheckStuds.CheckStuds = function(player: Player)
    local leaderstats = player:WaitForChild("leaderstats")
    local Studs = leaderstats:WaitForChild("Studs")

    local StudsFolder = game.Workspace:WaitForChild("Studs")

    for _, studModel in ipairs(StudsFolder:GetChildren()) do
        if studModel:IsA("Model") then
            local highlight = studModel:FindFirstChild("EffectHighlight"):IsA("Highlight")
            local studValue = studModel:FindFirstChild("Stud"):IsA("NumberValue")
            local touchPart = studModel:FindFirstChild("TouchPart"):IsA("Part")

            if highlight and studValue and touchPart then
                if Studs.Value >= studValue.Value then
                    highlight.Enabled = false
                    touchPart.CanTouch = false
                end
            end
        end
    end
end

return CheckStuds```
#

PS: I HAVE MINOR SCRIPTING EXPERIENCE

#

Pls Help

mighty thicket
#

Can you screenshoot you structure Studs folder or etc
Teamplate:

sharp junco
#

here is in replicatedstorage

#

oooh studfolder

#

here

mighty thicket
#
            local studValue = studModel:FindFirstChild("Stud"):IsA("NumberValue")

Huh

sharp junco
#

like the stage

mighty thicket
#

I think he cant find this

sharp junco
#

oh

mighty thicket
sharp junco
#

oh wait its called stage

#

i replaced it with sstage but it still doesnrt work

mighty thicket
#

What a Full name of the Stage now?

sharp junco
#

in the workspace its stage but i replaced studValue child with Stage instead of Stud

mighty thicket
#

Wait a bit i try to test this

sharp junco
#

k

mighty thicket
#

OOOOH

sour wagonBOT
#

studio** You are now Level 1! **studio

mighty thicket
#

I understood

#

:IsA() return true or false not a object

#
local CheckStuds = {}

CheckStuds.CheckStuds = function(player: Player)
    local leaderstats = player:WaitForChild("leaderstats")
    local Studs = leaderstats:WaitForChild("Studs")

    local StudsFolder = game.Workspace:WaitForChild("Studs")

    for _, studModel in ipairs(StudsFolder:GetChildren()) do
        if studModel:IsA("Model") then
            local highlight = studModel:FindFirstChild("EffectHighlight")
            local studValue = studModel:FindFirstChild("Stage")
            local touchPart = studModel:FindFirstChild("TouchPart")

            if highlight and studValue and touchPart then
                if Studs.Value >= studValue.Value then
                    highlight.Enabled = false
                    touchPart.CanTouch = false
                end
            end
        end
    end
end

return CheckStuds
#

Try this

sharp junco
#

ok

#

still doesnt work...

#

here is how i run the screipt on the client

#

local Framework = require(game.ReplicatedStorage.Framework)

game.Players.PlayerAdded:Connect(function(player)
Framework.Client.CheckStuds.CheckStuds(player)
end)

#

if that helps

mighty thicket
#

Okay how called Studs module in Framework?

sharp junco
#

the framework script?

#

local module = {}

local Types = require(script.Parent.Types)

function module.GetClient() : Types.Framework
local Table = {}

for _, module in script:GetChildren() do
    task.spawn(function()
        Table[module.Name] = require(module)
    end)
end

return Table

end

function module.GetServer() : Types.Framework
local CurrentService = game:GetService("RunService"):IsServer()

local Table = {}

if CurrentService then
    for _, module in game.ServerStorage.Modules:GetChildren() do
        task.spawn(function()
            Table[module.Name] = require(module)
        end)
    end
end

return Table

end

return {["Server"] = module.GetServer(), ["Client"] = module.GetClient()} or {["Client"] = module.GetClient()}

mighty thicket
#

Maybe you have smth in console? Mb Errors or etc
And i just add debug here

local CheckStuds = {}

CheckStuds.CheckStuds = function(player: Player)
    print(player)
    local leaderstats = player:WaitForChild("leaderstats")
    print()
    local Studs = leaderstats:WaitForChild("Studs")
    print(Studs)

    local StudsFolder = game.Workspace:WaitForChild("Studs")
    print(StudsFolder)

    for _, studModel in ipairs(StudsFolder:GetChildren()) do
        if studModel:IsA("Model") then
            local highlight = studModel:FindFirstChild("EffectHighlight")
            local studValue = studModel:FindFirstChild("Stage")
            local touchPart = studModel:FindFirstChild("TouchPart")

            if highlight and studValue and touchPart then
                if Studs.Value >= studValue.Value then
                    highlight.Enabled = false
                    touchPart.CanTouch = false
                else
                    warn(Studs.Value .. " < " .. studValue.Value)
                end
            else
                warn("Missing highlight, stud value, or touch part in " .. studModel.Name)
            end
        else
            warn(studModel.Name .. "Not a Model")
        end
    end
end

return CheckStuds
sharp junco
#

no

#

there are no warnings either

#

i run the function when the player joins on the client

mighty thicket
#

For now, I'll try to rewrite the Framework, and you try calling the CheckStuds function directly from the local script

sharp junco
#

ok

mighty thicket
#
local RunService = game:GetService("RunService")

local module = {}
local Types = require(script.Parent.Types)

local clientFramework = nil
local serverFramework = nil

local function buildFramework(modules)
    local framework = {
        Index = {},
        _errors = {}
    }

    for _, child in modules do
        table.insert(framework.Index, child.Name)
    end

    for _, child in modules do
        task.spawn(function()
            local success, result = pcall(require, child)
            if success then
                framework[child.Name] = result
            else
                framework._errors[child.Name] = result
                warn(("Failed to load module '%s': %s"):format(child.Name, result))
            end
        end)
    end

    return framework
end

function module.GetClient()
    if clientFramework == nil then
        clientFramework = buildFramework(script:GetChildren())
    end
    return clientFramework
end

function module.GetServer()
    if serverFramework == nil then
        if RunService:IsServer() then
            serverFramework = buildFramework(game.ServerStorage.Modules:GetChildren())
        else
            serverFramework = { Index = {}, _errors = {} }
        end
    end
    return serverFramework
end

return {
    Server = module.GetServer(),
    Client = module.GetClient(),
}

but no types idk how in your program but in Studio "function module.GetClient(): Types.Framework" its a Error (its Example)

#
local Framework = require(game.ReplicatedStorage.Framework)
local Client = Framework.Client

game.Players.PlayerAdded:Connect(function(player)
    Client.CheckStuds.CheckStuds(player)
end)

Call that in LocalScript

sharp junco
#

does it matter where the local script is?

#

i have it in playerscript

mighty thicket
sour wagonBOT
#

studio** You are now Level 2! **studio

mighty thicket
sharp junco
#

yeah i have it there but it doesnt work

mighty thicket
#

Huuuh

sharp junco
#

i have 8 studs on the leaderboard and it still is enabled the highlight

mighty thicket
#

You do its inGame or in Studio Testing?

sharp junco
#

studio testing

sour wagonBOT
#

studio** You are now Level 6! **studio

mighty thicket
#
local Framework = require(game.ReplicatedStorage.Framework)
local Client = Framework.Client
local player = game.Players.LocalPlayer
local RunService = game:GetService("RunService")

CheckStuds = RunService.RenderStepped:Connect(function()
    Client.CheckStuds.CheckStuds(player)
end)

-- you can Disconect this by using CheckStuds:Disconnect()

localScript
Sorry im stupid

sharp junco
#

so i disconnect it to stop it from spam checking?

mighty thicket
#

But its need delete debug (its Spamming console) and Maybe do other loop

sharp junco
#

if i do task.wait(0.1) or something like that?

mighty thicket
#

Ye its will be work, but its need rework later (For Optimization)

sharp junco
#

ok

mighty thicket
#

Its works right?

sharp junco
#

local Framework = require(game.ReplicatedStorage.Framework)
local Client = Framework.Client
local player = game.Players.LocalPlayer
local RunService = game:GetService("RunService")

CheckStuds = RunService.RenderStepped:Connect(function()
Client.CheckStuds.CheckStuds(player)
end)

task.wait(1)
CheckStuds:Disconnect() yeah it did before i did the disconnect thing

mighty thicket
#

If you disconnect it stop to work

sharp junco
#

ok but how do i get it to only check once bc its spamming the output

mighty thicket
#

Wait a bit

#
local CheckStuds = {}

CheckStuds.CheckStuds = function(player: Player)
    local leaderstats = player:WaitForChild("leaderstats")
    local Studs = leaderstats:WaitForChild("Studs")
    local StudsFolder = game.Workspace:WaitForChild("Studs")

    for _, studModel in ipairs(StudsFolder:GetChildren()) do
        if studModel:IsA("Model") then
            local highlight = studModel:FindFirstChild("EffectHighlight")
            local studValue = studModel:FindFirstChild("Stage")
            local touchPart = studModel:FindFirstChild("TouchPart")

            if highlight and studValue and touchPart then
                if Studs.Value >= studValue.Value then
                    highlight.Enabled = false
                    touchPart.CanTouch = false
                end
            end
        end
    end
end

return CheckStuds
#

Just delete prints, warns

sharp junco
#

thank you so much for helping 🙂

mighty thicket
#

I'm always happy to help

mighty thicket
sharp junco
#

yeah