Ad
Log in to vote
0

How do I use a leaderstat value for a shop?

Asked by 11 months ago
Edited 11 months ago

Hey!! I am trying to make an old style shop where you walk into a part and if you have enough "Cash" then you can go past, if not, nothing happens. Here is my local script in the part

`local leaderstarts = game.Players.LocalPlayer:WaitForChild("leaderstats"):WaitForChild("Cash") local part = script.Parent local function OnTouch(part) if leaderstarts.Value >= 10 then script.Parent.Transparency = 1 script.Parent.CanCollide = false print("Your not poor") else print("Wow your poor") end

end`

0
Also how do I make this look like script so that you can see exactly what I wrote? austenman123 2 — 11mo

1 answer

Log in to vote
0
Answered by
TechModel 118
11 months ago
Edited 11 months ago

Locals scripts don't work when it is in a part on workspace I think. What I've done here is you put the part that you want to walk through and put it in ReplicatedStorage. Create a local script and put it in StarterGui.

local leaderstarts = game.Players.LocalPlayer:WaitForChild("leaderstats"):WaitForChild("Cash")
local part = game.ReplicatedStorage.Part -- Gets the part from replicated
local clone = part:Clone() -- Clones all individial local parts to each player

clone.Parent = workspace
db = false

clone.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        if db == false then
            db = true

            local plr = game.Players:GetPlayerFromCharacter(hit.Parent)

        if plr.leaderstats.Cash.Value >= 10 then
                clone.Transparency = 1
                clone.CanCollide = false
                print("Your not poor")
                wait(1) -- Adjust time to extend the duration of the opening
                clone.Transparency = 0
                clone.CanCollide = true
                db = false
            else
                print("Wow your poor")
            end 
        end 
    end
end)

See if that works. Also, what is happening is cloning the part in the ReplicatedStorage and clones to players individually which only makes the part transparent locally.

Ad

Answer this question