I want to make a simulator gate, it works, BUT I want to make it unlocked for the person who unlocked it(just like how pet sim 99 has that working). The problem is that if the first person in the server unlocks it, it will be unlocked for everyone. Here’s my script if you need it, and any help is appreciated! This is a gate save script because I have saved the values such as the player’s area.
--local player = game.Players
game.Players.PlayerAdded:Connect(function(player)
wait(1)
if player ~= nil then
if player:WaitForChild("PlayerValues"):WaitForChild("Area").Value >= 2 then
script.Parent:Destroy()
--script.Parent.Transparency = 1
--script.Parent.CanCollide = false
--game.Workspace.Map["1"].Door.Transparency = 1
--game.Workspace.Map["1"].Door.CanCollide = false
--game.Workspace.Map["1"].Door.SurfaceGui.AreaLabel.Visible = false
--game.Workspace.Map["1"].Door.SurfaceGui.CoinImage.Visible = false
--game.Workspace.Map["1"].Door.SurfaceGui.BuyButton.Visible = false
end
end
end)
The script that unlocks it is by a GUI button that fires a remote event and here’s the script for it.
local ReplicatedStorage = game.ReplicatedStorage
script.Parent.Activated:Connect(function()
ReplicatedStorage.BuyRemoteEvent:FireServer()
--if buyingPlayer.leaderstats.Coins.Value >= game.Workspace.Map[buyingPlayer:WaitForChild("buyingPlayerValues"):WaitForChild("Area").Value].Door.Cost.Value then
--buyingPlayer.leaderstats.Coins.Value -= game.Workspace.Map[buyingPlayer:WaitForChild("buyingPlayerValues"):WaitForChild("Area").Value].Door.Cost.Value
--end
end)
And this is the script in ServerScriptService that does the thing when the script above activates the remote event.
--local player = game.Players.LocalPlayer
local ReplicatedStorage = game.ReplicatedStorage
ReplicatedStorage.BuyRemoteEvent.OnServerEvent:Connect(function(buyingPlayer)
-- change the stat value
buyingPlayer.leaderstats.Coins.Value -= game.Workspace.Map[buyingPlayer:WaitForChild("PlayerValues"):WaitForChild("Area").Value].Door.Cost.Value
-- any other changes could happen here as well, like rewarding the item they bought
game.Workspace.Map[buyingPlayer:WaitForChild("PlayerValues"):WaitForChild("Area").Value].Door:Destroy()
--game.Workspace.Map[buyingPlayer:WaitForChild("PlayerValues"):WaitForChild("Area").Value].Door.Transparency = 1
--game.Workspace.Map[buyingPlayer:WaitForChild("PlayerValues"):WaitForChild("Area").Value].Door.CanCollide = false
--game.Workspace.Map[buyingPlayer:WaitForChild("PlayerValues"):WaitForChild("Area").Value].Door.SurfaceGui.AreaLabel.Visible = false
--game.Workspace.Map[buyingPlayer:WaitForChild("PlayerValues"):WaitForChild("Area").Value].Door.SurfaceGui.CoinImage.Visible = false
--game.Workspace.Map[buyingPlayer:WaitForChild("PlayerValues"):WaitForChild("Area").Value].Door.SurfaceGui.BuyButton.Visible = false
buyingPlayer.PlayerValues:WaitForChild("Area").Value += 1
end)