Hi, i am searching for change my script.
It works when a player added the game but not ingame when his rebirths count is 1 or 2.
the localsript is in StarterPlayerScripts:
Players = game:GetService(“Players”)
Players.PlayerAdded:Connect(function(player)
local Part = script.Parent
local PlayerStorages = game.ServerStorage:WaitForChild("PlayerStorage")
local plr = PlayerStorages:WaitForChild(player.Name)
local cur = plr:WaitForChild("Currencys")
local rebirth = cur:WaitForChild("Rebirths").Value
local gui = game.StarterGui.ScreenGui.Frame
if rebirth >= 1 then
gui.Visible = true
Part.Transparency = 1
Part.CanCollide = false
end
local Players = game:GetService(“Players”)
local Part = script.Parent
local PlayerStorages = game.ServerStorage:WaitForChild("PlayerStorage")
local plr = PlayerStorages:WaitForChild(player.Name)
local cur = plr:WaitForChild("Currencys")
local rebirth = cur:WaitForChild("Rebirths").Value
local gui = Players.LocalPlayer.PlayerGui:WaitForChild("ScreenGui").Frame
Players.PlayerAdded:Connect(function()
while wait(1) do
if rebirth >= 1 then
gui.Visible = true
Part.Transparency = 1
Part.CanCollide = false
end
end
end)
Why are you storing a rebirth value in ServerStorage when the client can’t even access it? Here is a basic leaderstats script that saves for your game, put it in ServerScriptService:
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local playerData = DataStoreService:GetDataStore("PlayerData")
local function onPlayerJoin(player) -- Runs when players join
local leaderstats = Instance.new("Folder") --Sets up leaderstats folder
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local currencyfolder = Instance.new("Folder")
currencyfolder.Name = "Currencys"
currencyfolder.Parent = leaderstats
local Rebirths = Instance.new("IntValue") --Sets up value for leaderstats
Rebirths.Name = "Rebirths"
Rebirths.Parent = currencyfolder
local playerUserId = "Player_" .. player.UserId --Gets player ID
local data = playerData:GetAsync(playerUserId) --Checks if player has stored data
if data then
Rebirths.Value = data['Rebirths']
else
-- Data store is working, but no current data for this player
Rebirths.Value = 0
end
end
local function create_table(player)
local player_stats = {}
for _, stat in pairs(player:WaitForChild("leaderstats").Currencys:GetChildren()) do
player_stats[stat.Name] = stat.Value
end
return player_stats
end
local function onPlayerExit(player) --Runs when players exit
local player_stats = create_table(player)
local success, err = pcall(function()
local playerUserId = "Player_" .. player.UserId
playerData:SetAsync(playerUserId, player_stats) --Saves player data
end)
if not success then
warn('Could not save data!')
end
end
Players.PlayerAdded:Connect(onPlayerJoin)
Players.PlayerRemoving:Connect(onPlayerExit)
And here is your fixed original script:
local Part = script.Parent
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local PlayerGui = LocalPlayer:WaitForChild("PlayerGui")
local Gui = PlayerGui:WaitForChild("ScreenGui")
local PlayerStorages = LocalPlayer:WaitForChild("leaderstats")
local cur = PlayerStorages:WaitForChild("Currencys")
local rebirth = cur:WaitForChild("Rebirths")
local Frame = Gui:FindFirstChild("Frame")
rebirth:GetPropertyChangedSignal("Value"):Connect(function(NewValue)
if NewValue >= 1 then
Frame.Visible = true
Part.Transparency = 1
Part.CanCollide = false
end
end)