Button Press for Points
Where to put it
Where to put it
LocalScript
LocalScript
-- We must get the UserInputService before we can use it
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local addPointEvent = ReplicatedStorage:WaitForChild("AddPoint")
-- A sample function providing one usage of InputBegan
local function onInputBegan(input, gameProcessed)
if input.KeyCode == Enum.KeyCode.Space then
addPointEvent:FireServer()
end
end
UserInputService.InputBegan:Connect(onInputBegan)
Script
Script
local function onPlayerJoin(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local points= Instance.new("IntValue")
points.Name = "Points"
points.Value = 50
points.Parent = leaderstats
end
game.Players.PlayerAdded:Connect(onPlayerJoin)
-- Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local addPointEvent = Instance.new("RemoteEvent", ReplicatedStorage)
addPointEvent.Name = "AddPoint"
local function addPoints(player)
local p = game.Players:FindFirstChild(player.Name)
if p then
p.leaderstats.Points.Value = p.leaderstats.Points.Value + 1
end
end
addPointEvent.OnServerEvent:Connect(addPoints)