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

Door script wont save and opens for every player in the client?

Asked by 5 years ago
Edited 5 years ago

**I'm currently making a Simulator game with a special Kill Door system. Through killing monsters you will obtain kills from the leaderstats and if you reached the 100 kills the door will unlock and save itself. But i don't really know where i made the mistake

If i am in roblox studio the door will unlock and save itself, but in the client the door will also unlock if i reach the 100 kills, but when i rejoin the door isnt gone while i have 100 kills.

Another problem.. When a player in the client reached the 100 Kills, the door will not only unlock for him but also for everyone else in the client. How do i fix this problem **

--// Services

local Players = game:GetService("Players")

--// Variables

local door = game.Workspace.FirstDoor

--// Main Code

local function CheckKill(val) if val >= 100 then door:Destroy() else print("Not enough") end end

Players.PlayerAdded:Connect(function(Player) local leaderstats = Player:WaitForChild("leaderstats") local killStat = leaderstats:WaitForChild("Kills") CheckKill(killStat.Value) leaderstats.Kills.Changed:Connect(function(Value) CheckKill(Value) end) end)

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

A couple things here. It appears as though you're missing a way to save kills. Do this with something called a Datastore! Read about them here cause you'll learn more: https://developer.roblox.com/en-us/articles/Data-store

Also consider destroying the door on the local side of things from a local script.

If you implement a datastore, this should solve your issues!

1
^^ Syntheix 7 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

Now, I am fairly new to scripting, but it seem like when the door destroys, it is being replicated to EVERYBODY.

I am guessing that you want a object to be replicated only to a specific player. I recommend using a LocalScript so you can replicate only a specific object to a specific player.

Just my 2 cents.

Answer this question