I tried that, but for some reason I get this error:
Door is not a valid member of Folder “Workspace.Houses” - Client - HousePurchaseClient:1
HousePurchaseClient Script
I tried that, but for some reason I get this error:
Door is not a valid member of Folder “Workspace.Houses” - Client - HousePurchaseClient:1
HousePurchaseClient Script
Can you copy the code out into this discussion for easier debugging?
The HousePurchase Client script is this:
local ProximityPrompt = workspace.Houses.Door.ProximityPrompt
local doorOwnerId = script.Parent.Parent:GetAttribute("Owner")
ProximityPrompt.Triggered:Connect(function(player)
if player.UserId == doorOwnerId then
if ProximityPrompt.ActionText == "Lock House" then
script.Parent.CanCollide = true
script.Parent.Transparency = 0
ProximityPrompt.ActionText = "Unlock House"
else
script.Parent.CanCollide = false
script.Parent.Transparency = 0.7
ProximityPrompt.ActionText = "Lock House"
end
end
end)
lmk if you need any other code.
Try this:
local ProximityPrompt = workspace:WaitForChild("Houses"):WaitForChild("Door"):WaitForChild("ProximityPrompt")
local doorOwnerId = script.Parent.Parent:GetAttribute("Owner")
ProximityPrompt.Triggered:Connect(function(player)
if player.UserId == doorOwnerId then
if ProximityPrompt.ActionText == "Lock House" then
script.Parent.CanCollide = true
script.Parent.Transparency = 0
ProximityPrompt.ActionText = "Unlock House"
else
script.Parent.CanCollide = false
script.Parent.Transparency = 0.7
ProximityPrompt.ActionText = "Lock House"
end
end
end)
All it does is waits for all the directories, which is what I did to fix a similar issue.
That fixed it, thanks! However, the leaderstat still doesn’t update when the money is removed. It does show in the output though.
Are you sure it’s a leaderstat? Can I see the script that creates the leaderstat?
This is the leaderstat module script:
local module = {}
function module:Create(player: Player, profile)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local coin = Instance.new("IntValue")
coin.Name = "Coin"
coin.Value = profile.Data.Coin
coin.Parent = leaderstats
end
return module
This is the datamanger module script:
local Players = game:GetService("Players")
local serverScriptService = game:GetService("ServerScriptService")
local modules = serverScriptService:WaitForChild("Modules")
local ProfileService = require(modules:WaitForChild("ProfileService"))
local template = require(script:WaitForChild("Template"))
local leaderstats = require(script:WaitForChild("Leaderstats"))
local datakey = "_DataStore"
local profileStore = ProfileService.GetProfileStore(datakey, template).Mock
local dataManager = {}
dataManager.Profiles = {}
function dataManager.GetProfile(player)
if not player:IsDescendantOf(Players) then return end
local profile = dataManager.Profiles[player]
while profile == nil do
profile = dataManager.Profiles[player]
task.wait()
end
return profile
end
local function PlayerAdded(player: Player)
local profile = profileStore:LoadProfileAsync("Player_"..player.UserId)
if profile ~= nil then
profile:AddUserId(player.UserId)
profile:Reconcile()
profile:ListenToRelease(function()
dataManager.Profiles[player] = nil
player:Kick()
end)
if player:IsDescendantOf(Players) then
dataManager.Profiles[player] = profile
leaderstats:Create(player, profile)
else
profile:Release()
end
else
player:Kick()
end
end
local function PlayerRemoving(player: Player)
local profile = dataManager.Profiles[player]
if profile ~= nil then
profile:Release()
end
end
for _, player in Players:GetPlayers() do
task.spawn (PlayerAdded, player)
end
Players.PlayerAdded:Connect(PlayerAdded)
Players.PlayerRemoving:Connect(PlayerRemoving)
return dataManager
If you are creating it, why would you use this? Wouldn’t it be 0? (sorry if im wrong)
Why can’t you just use datastore service? It would be much easier. Here is a really simple script:
local dss = game:GetService("DataStoreService")
local coinsDS = dss:GetDataStore("Levels")
function saveData(player)
pcall(function()
local coins = player.leaderstats.Coins.Value
coinsDS:SetAsync(player.UserId .. "Level", {coins})
end)
end
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "Leaderstats"
local coinsVal = Instance.new("IntValue", leaderstats)
coinsVal.Name = "Coins"
coinsVal.Value = 1
pcall(function()
local data = coinsDS:GetAsync(player.UserId .. "Coins")
if data then
coinsVal.Value = data[1]
end
end)
end)
game.Players.PlayerRemoving:Connect(saveData)
game:BindToClose(function()
for i, player in pairs(game.Players:GetPlayers()) do
saveData(player)
end
end)
If you use this, please tell me if it doesn’t work. Also it goes in serverscriptservice
Otherwise, I can’t find out why it doesn’t take away the leaderstat
Where am i to put this code in sss? I did use profileservice because I found online that it was the best one to use.
I do have a template module which contains
local template = { Coin = 0, } return template
Yes. I’ll test it out quickly.