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

Okay, another question. This time, I need to know what is wrong with this script, anybody know how?.

Asked by 4 years ago
Edited 4 years ago

local original = game.ServerStorage.BasicFamilyHome

local clone = original:Clone()

if game.Players.LocalPlayer.leaderstats.Money.Value >= game.ReplicatedStorage.StarterHousePrice.Value then

script.Parent.ReplicatedStorage.BoughtStarterHouse.Value = 1
clone.Parent = workspace
print("Sucessfully loaded the starter house!")

else

script.Parent.ReplicatedStorage.BoughtStarterHouse.Value = 0
print("bruh no monei m8")

end

That is meant to clone a house in ServerStorage if the player's cash is 50 or above. I already defined how much it is by an intvalue in replicatedstorage. I'd like help, thx :)

0
automatically or on a touched brick or a button gui PastorCL3Z 75 — 4y

1 answer

Log in to vote
2
Answered by 4 years ago

Hello. A LocalScript cannot access ServerStorage as it is only for the server. Instead, use ReplicatedStorage. Note that the house will only show up for the player not the rest of the server, so try using RemoteEvents . Also, I used :WaitForChild() on the player's leaderstats as LocalScripts execute before ServerScripts so the leaderstats might not be created yet. I also added a repeat wait() until statement until the player's character and the game is loaded. Try this:

repeat wait() until game:IsLoaded() and game.Players.LocalPlayer.Character

local original = game.ReplicatedStorage.BasicFamilyHome

local clone = original:Clone()

if game.Players.LocalPlayer:WaitForChild("leaderstats").Money.Value >= game.ReplicatedStorage.StarterHousePrice.Value then

script.Parent.ReplicatedStorage.BoughtStarterHouse.Value = 1
    clone.Parent = workspace
    print("Sucessfully loaded the starter house!")
else
    script.Parent.ReplicatedStorage.BoughtStarterHouse.Value = 0
    print("bruh no monei m8")
end

Please accept this answer and upvote it if it helped.

0
Okay thanks! It's meant to be a one player game so i dont really mind if the "other players" cant see it :) KingIce1310 23 — 4y
0
No problem. Please accept my answer. youtubemasterWOW 2741 — 4y
Ad

Answer this question