I’m trying to have a player press a key at a certain time and when they press it on time, it adds + 1 to a value. It doesn’t work, but when I look at the output, it says that there are 0 errors. No way for me to try and find the problem.
Here’s the script I have:
function onTouched(hit)
game.Workspace.DrinkPart.bg.g.Enabled = true
wait(.5)
game.Workspace.DrinkPart.bg.g.Enabled = false
end
connection = script.Parent.Touched:connect(onTouched)
local player = game:GetService("Players")
if game.Workspace.DrinkPart.bg.g.Enabled == true then
function keyDown(key)
if key == "F" then
player.leaderstats.BottlesDrank.Value = player.leaderstats.BottlesDrank.Value + 1
end
end
end ```
You defined player as a service, and tried to access leaderstats from it.
You’d need to use a remote to award the player on the server.
Try this:
local Replicated = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local Player = players.LocalPlayer
local workspace = game:GetService("Workspace")
local Uis = game:GetService("UserInputService")
local function onTouched(hit)
workspace:WaitForChild("DrinkPart").bg.g.Enabled = true
task.wait(0.5)
workspace:WaitForChild("DrinkPart").bg.g.Enabled = false
end
local connection = script.Parent.Touched:connect(onTouched)
Uis.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.F then
if workspace:WaitForChild("DrinkPart").bg.g.Enabled == true then
Replicated:WaitForChild("MyRemote"):FireServer()
end
end
end)
I’ll now continue editing it.
Server Side
local Replicated = game:GetService("ReplicatedStorage")
Replicated:FindFirstChild("MyRemote").OnServerEvent:Connect(function(Player)
Player.leaderstats.BottlesDrank.Value += 1
end)
Its not working for me. I edited the script to match yours, I made a new remote event, and put that second script part in server script service but it does not work still. Perhaps its the type of scripts I have.
The first script part is a local script, and the second script part is a normal script. Should those be changed?