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

How to make a buy zone area that costs 100?

Asked by 3 years ago
Edited 3 years ago

I'm trying to make a simulator game and I want to make a zone and you have to pay 100 cash. I am using this script right now:

local Player = game.Players.LocalPlayer

local leaderstats = game.ServerScriptService.Value.leaderstats.Cash

local Zone = game.Workspace.Zone

Zone.Touched:Connect(function(hit) if Player.leaderstats >= 100 then Zone.Transparency = 1 Zone.CanCollide = false end end)

For some reason, it doesnt work. Help?

0
if leaderstats >= 100* greatneil80 2647 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

Local scripts change things on the client (players computer only visible to them) Scripts change things on the server (which everyone can see)

I recommend having the "script" which checks of the player can afford the plot to be placed inside the Zone object.

local function getPlayerFromCharacter(character)
    for _, player in pairs(game:GetService("Players"):GetPlayers()) do
        if player.Character == character then
            return player
        end
    end
end

Zone.Touched:Connect(function(hit)
    If hit.parent.Humanoid then
        local player = getPlayerFromCharacter(hit.parent)
        if (the players leaderboard allows it) then
            --do your stuff
        end
    end
end)
0
Sorry if theres some bugs I'm on mobile and haven't tested it - hopefully it isn't too bad! AlexTheCreator 461 — 3y
Ad

Answer this question