Hi everyone, i just made a leaderboard that save players points, it works, but the problem is when player click to earn points it doesn’t save on the leaderboard.
the local script that give you points, it is inside of StarterCharacterScripts:
Starts here:
local UIS = game:GetService(“UserInputService”)
local picked_up_sandwich = false
local sandwich = nil
UIS.InputBegan:Connect(function(input)
local ray = workspace.Camera:ViewportPointToRay(UIS:GetMouseLocation().X, UIS:GetMouseLocation().Y)
if input.UserInputType == Enum.UserInputType.MouseButton1 and not picked_up_sandwich then
for i,v in pairs(workspace:GetDescendants()) do
if v.ClassName == "UnionOperation" and (ray.Origin + ray.Direction * (ray.Origin - v.Position).Magnitude - v.Position).Magnitude <= 1 or v.ClassName == "UnionOperation" and v.Name ~= "Baseplate" and (ray.Origin + ray.Direction * (ray.Origin - v.Position).Magnitude - v.Position).Magnitude <= 1 then
picked_up_sandwich = true
sandwich = v
local connection = nil
connection = game:GetService("RunService").RenderStepped:Connect(function()
if not picked_up_sandwich then connection:Disconnect() return end
local ray = workspace.Camera:ViewportPointToRay(UIS:GetMouseLocation().X, UIS:GetMouseLocation().Y)
sandwich.Position = ray.Origin + ray.Direction * 15
sandwich.Orientation = Vector3.new(0,0,0)
sandwich.CanCollide = false
end)
end
end
elseif input.UserInputType == Enum.UserInputType.MouseButton1 and picked_up_sandwich then
for i,v in pairs(workspace:GetDescendants()) do
if v.ClassName == "Attachment" and v.Name == sandwich.Name and (ray.Origin + ray.Direction * (ray.Origin - v.WorldPosition).Magnitude - v.WorldPosition).Magnitude <= 1 then
local new_sandwich = sandwich
game:GetService("RunService").RenderStepped:Connect(function()
new_sandwich.Position = v.WorldPosition
new_sandwich.Orientation = Vector3.new(0,0,0)
new_sandwich.CanCollide = false
end)
end
end
picked_up_sandwich = false
local player = game.Players.LocalPlayer
player.leaderstats.Level.Value = player.leaderstats.Level.Value + 1
local RogerEating = game.Workspace.RogerEating
local eatingSound = game.Workspace.Sounds.Eating
RogerEating.Position = Vector3.new(112.64, 4.91, 55.799)
eatingSound:Play()
wait(0.09)
RogerEating.Position = Vector3.new(137.266, 4.91, 55.799)
wait(0.009)
RogerEating.Position = Vector3.new(112.64, 4.91, 55.799)
eatingSound:Play()
wait(0.09)
RogerEating.Position = Vector3.new(137.266, 4.91, 55.799)
sandwich.CanCollide = true
sandwich:Destroy()
sandwich = nil
local food = game.Workspace.Cool
local clonedFood = food:Clone()
clonedFood.Parent = game.Workspace
clonedFood.Position = Vector3.new(107.914, 3.236, 55.777)
end
Sorry, the FireServer function, only works in the client. Here a little change for the LocalScript.
local ray = workspace.Camera:ViewportPointToRay(UIS:GetMouseLocation().X, UIS:GetMouseLocation().Y)
if input.UserInputType == Enum.UserInputType.MouseButton1 and not picked_up_sandwich then
for i,v in pairs(workspace:GetDescendants()) do
if v.ClassName == "UnionOperation" and (ray.Origin + ray.Direction * (ray.Origin - v.Position).Magnitude - v.Position).Magnitude <= 1 or v.ClassName == "UnionOperation" and v.Name ~= "Baseplate" and (ray.Origin + ray.Direction * (ray.Origin - v.Position).Magnitude - v.Position).Magnitude <= 1 then
picked_up_sandwich = true
sandwich = v
local connection = nil
connection = game:GetService("RunService").RenderStepped:Connect(function()
if not picked_up_sandwich then connection:Disconnect() return end
local ray = workspace.Camera:ViewportPointToRay(UIS:GetMouseLocation().X, UIS:GetMouseLocation().Y)
sandwich.Position = ray.Origin + ray.Direction * 15
sandwich.Orientation = Vector3.new(0,0,0)
sandwich.CanCollide = false
end)
end
end
elseif input.UserInputType == Enum.UserInputType.MouseButton1 and picked_up_sandwich then
for i,v in pairs(workspace:GetDescendants()) do
if v.ClassName == "Attachment" and v.Name == sandwich.Name and (ray.Origin + ray.Direction * (ray.Origin - v.WorldPosition).Magnitude - v.WorldPosition).Magnitude <= 1 then
local new_sandwich = sandwich
game:GetService("RunService").RenderStepped:Connect(function()
new_sandwich.Position = v.WorldPosition
new_sandwich.Orientation = Vector3.new(0,0,0)
new_sandwich.CanCollide = false
end)
end
end
picked_up_sandwich = false
local event = game.ReplicatedStorage.Action
event:FireServer(1)
local RogerEating = game.Workspace.RogerEating
local eatingSound = game.Workspace.Sounds.Eating
RogerEating.Position = Vector3.new(112.64, 4.91, 55.799)
eatingSound:Play()
wait(0.09)
RogerEating.Position = Vector3.new(137.266, 4.91, 55.799)
wait(0.009)
RogerEating.Position = Vector3.new(112.64, 4.91, 55.799)
eatingSound:Play()
wait(0.09)
RogerEating.Position = Vector3.new(137.266, 4.91, 55.799)
sandwich.CanCollide = true
sandwich:Destroy()
sandwich = nil
local food = game.Workspace.Cool
local clonedFood = food:Clone()
clonedFood.Parent = game.Workspace
clonedFood.Position = Vector3.new(107.914, 3.236, 55.777)
end
Server Script →
local remote = game.ReplicatedStorage.Action
remote.OnServerEvent:Connect(function(player,giving)
player.leaderstats.Level.Value += giving
end)
-- [ Just remove the fire event function.