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
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)


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:

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"

Ad

Answer this question