Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 4 years ago
Edited 4 years ago
01local UserInputService = game:GetService("UserInputService")
02local leaderstats = Instance.new("Folder", game.Players.LocalPlayer)
03        local Respect = Instance.new("IntValue", leaderstats)
04        leaderstats.Name = "leaderstats"
05        Respect.Name = "Respect"
06 
07 
08UserInputService.InputBegan:Connect(function(input, event)
09    if input.KeyCode == Enum.KeyCode.F then
10        local audio = workspace:FindFirstChild("RESPECT THE VETS")
11        audio.Playing = true
12        Respect.Value = Respect.Value + 1
13    end
14end)

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:

01game.Players.PlayerAdded:Connect(function(player)
02    local UserInputService = game:GetService("UserInputService")
03    local leaderstats = Instance.new("Folder", player)
04    local Respect = Instance.new("IntValue", leaderstats)
05    leaderstats.Name = "leaderstats"
06    Respect.Name = "Respect" --everything works until the line after this
07        UserInputService.InputBegan:Connect(function(input, event) --doesnt work
08            if input.KeyCode == Enum.KeyCode.F then
09                local audio = workspace:FindFirstChild("RESPECT THE VETS")
10                audio.Playing = true
11                Respect.Value = Respect.Value + 1
12        end
13    end)
14end)
0
maybe try creating the leaderstats and value on the server. might be one of the causes. bnxDJ 57 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

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:

01game.Players.PlayerAdded:Connect(function(player)
02    local UserInputService = game:GetService("UserInputService")
03    local leaderstats = Instance.new("Folder", player)
04    local Respect = Instance.new("IntValue", leaderstats)
05    leaderstats.Name = "leaderstats"
06    Respect.Name = "Respect"
07end)
08 
09game.ReplicatedStorage.GiveRespect.OnServerEvent:Connect(function(plr)
10    plr.leaderstats.Respect.Value = plr.leaderstats.Respect.Value + 1
11end)

local script:

01local plr = game.Players.LocalPlayer
02local audio = workspace:FindFirstChild("RESPECT THE VETS")
03local UIS = game:GetService("UserInputService")
04 
05UIS.InputBegan:Connect(function(input)
06    if input.KeyCode == Enum.KeyCode.F then
07        audio:Play()
08        game.ReplicatedStorage.GiveRespect:FireServer(plr)
09    end
10end)

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

Ad

Answer this question