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

Is this script correct? (I have no confidence in it being correct)

Asked by 6 years ago

Okay. So this script is supposed to save what houses the player has bought and make it so that they are still usable by the player after the player has left the game and returned. I am not at all confident in the script being correct and I don't want to waste hours earning the money to buy the house in my game only to see that the script didn't work. Here is the script:

local plr = game.Players.LocalPlayer
local washousePurchased = false
local uniquekey = 'id-'..plr.UserID

if script.Parent.MouseClick and plr.leaderstats.Money.Value >= 150 then --if the clickdetector that is the script's parent got clicked while the player's money value was 150 or up, the house was automatically purchased, so essentially this is just seeing if the house was bought
    washousePurchased = true --purchasing the house makes the value true
    if washousePurchased == true then
        game.Players.PlayerAdded:connect(function()
            game.Workspace["Uncommon House"].Door.CanCollide = false --makes the house's door's cancollide value false so that the person who bought it can get in
        end)
    end
end
--i bet i made 1000 different errors here, don't make fun of me i am a total scripting nub :P
0
I'm no perfect raspberry pudding but something caught my eye immediately. LocalPlayer is a local script variable and mouseClick is server script to use this one instead. MachoPiggies 526 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

Try this script if it isn't working.

game.Players.PlayerAdded:connect(function(plr)
    local washousePurchased = false
    local uniquekey = 'id-'..plr.UserID
    if script.Parent.MouseClick and plr.leaderstats.Money.Value >= 150 then 
        washousePurchased = true 
        if washousePurchased == true then
                game.Workspace["Uncommon House"].Door.CanCollide = false
        end
    end
end)
Ad

Answer this question