How's your day been?
I have discovered a problem with your code.
I'm pretty sure you can't use game.Players.LocalPlayer in a script, and I'm also pretty sure you can't use the .Touched function in a LocalScript.
Let me fix this problem for you.
Go to the Home Tab and select Game Settings, then select Security. Then turn on 'Enable Studio to API Services'.
While your in the Security tab, you might as well turn on 'Allow HTTP requests' so the server can issue remote events.
Alright, now time for the second thing to do.
Insert a script inside ServerScriptService, and type in (or copy and paste) this code:
local store = game:GetService("DataStoreService")
local data = store:GetDataStore("Minutes")
game.Players.PlayerAdded:Connect(function(plr)
local getData = data:GetAsync(plr.UserId) or 0
local leaderstats = Instance.new("Folder",plr)
leaderstats.Name = "leaderstats"
local mins = Instance.new("NumberValue",leaderstats)
mins.Name = "Minutes"
mins.Value = getData
while wait(60) do
mins.Value += 1
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
data:SetAsync(plr.UserId,plr.leaderstats.Minutes.Value)
end)
Now, onto your ACTUAL script!
Just kidding! Before all that you need to do 2 more things!
Add a RemoteEvent in ReplicatedStorage called "GetPlr".
Insert a LocalScript inside StarterPack and insert this script inside:
warn("Hello! This is a message from "..script.Name..". Giving the server the player...")
game.ReplicatedStorage.GetPlr:FireServer()
Now, FINALLY we're onto what you read this for! Your ACTUAL SCRIPT!
Just kidding! Before that you have to-
Okay, but seriously, here's the script!
game.ReplicatedStorage.GetPlr.OnServerEvent:Connect(function(plr)
warn("Hello! The server has responded!")
if plr.leaderstats.Minutes.Value <= 100 then
print("Player is not hacking. Good job, player, for having the decency on not to hack!")
end
script.Parent.Touched:Connect(function()
if plr.leaderstats.Minutes.Value < 100 then
plr:Kick("Kicked | Hacking")
end
end)
end)
This took a while, but it's ALL worth it to help people having problems!
With nothing else to say, goodbye, and tell me if you have any more errors or bugs.
Have a good day!
1 comment
please elaborate, also fix the formatting (use the buttons on top of the text box).