Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

[EASY] This script halfway works, but there is one MAJOR flaw?!

local UserInputService = game:GetService("UserInputService")
local leaderstats = Instance.new("Folder", game.Players.LocalPlayer)
		local Respect = Instance.new("IntValue", leaderstats)
		leaderstats.Name = "leaderstats"
		Respect.Name = "Respect"


UserInputService.InputBegan:Connect(function(input, event)
	if input.KeyCode == Enum.KeyCode.F then
		local audio = workspace:FindFirstChild("RESPECT THE VETS")
		audio.Playing = true
		Respect.Value = Respect.Value + 1
	end
end)

this script works mostly, what happens in game when I use it is: -creates the leaderstats value and folder -when clicked F it plays the noise but what doesnt work is: -value doesnt have the correct name on the leaderboard -value does not increase

there is no output errors. it is in a localscript inside of StarterGui if you want to know that i will be glad to elaborate

modified version, server script in ServerScriptService:

game.Players.PlayerAdded:Connect(function(player)
	local UserInputService = game:GetService("UserInputService")
	local leaderstats = Instance.new("Folder", player)
	local Respect = Instance.new("IntValue", leaderstats)
	leaderstats.Name = "leaderstats"
	Respect.Name = "Respect" --everything works until the line after this
		UserInputService.InputBegan:Connect(function(input, event) --doesnt work
    		if input.KeyCode == Enum.KeyCode.F then
       	 		local audio = workspace:FindFirstChild("RESPECT THE VETS")
       	 		audio.Playing = true
       	 		Respect.Value = Respect.Value + 1
   		end
	end)
end)
		
			

1 comment

0

maybe try creating the leaderstats and value on the server. might be one of the causes.

1 answer

✓ Accepted answer

try using making a remove event called "GiveRespect" and then place it on replicated storage then create a server script located on server script service and then make a local script and place it on starter player > starter player scripts

server script:

game.Players.PlayerAdded:Connect(function(player)
    local UserInputService = game:GetService("UserInputService")
    local leaderstats = Instance.new("Folder", player)
    local Respect = Instance.new("IntValue", leaderstats)
    leaderstats.Name = "leaderstats"
    Respect.Name = "Respect"
end)

game.ReplicatedStorage.GiveRespect.OnServerEvent:Connect(function(plr)
	plr.leaderstats.Respect.Value = plr.leaderstats.Respect.Value + 1
end)

local script:

local plr = game.Players.LocalPlayer
local audio = workspace:FindFirstChild("RESPECT THE VETS")
local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.F then
		audio:Play()
		game.ReplicatedStorage.GiveRespect:FireServer(plr)
	end
end)

also you got an unused parameter on the user input service called "event"

This discussion is preserved as it was. New answers, comments, and votes are closed.