Debounce is not a valid member of Folder - lua

Alright so I got this script from a tutorial and this is what I typed for the script Remotes
local replicatedStorage = game:GetService("ReplicatedStorage")
local remoteData = game:GetService("ServerStorage"):WaitForChild("RemoteData")
local cooldown = 1
replicatedStorage.Remotes.Lift.OnServerEvent:Connect(function(player)
print("event launched")
if not remoteData:FindFirstChild(player.Name) then return "NoFolder" end
local debounce = remoteData[player.Name].Debounce
if not debounce then
debounce.Value = true
player.leaderstats.Power.Value = player.leaderstats.Power.Value + 5 * (player.leaderstats.Prestiges.Value + 1)
wait(cooldown)
debounce.Value = false
end
end)
but I have seem to get the error which is
Debounce is not a valid member of Folder "ServerStorage.RemoteData.OmegaHero2010"
here are some other scripts
Stats
local serverStorage = game:GetService("ServerStorage")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local power = Instance.new("NumberValue")
power.Name = "Power"
power.Parent = leaderstats
local prestige = Instance.new("NumberValue")
prestige.Name = "Prestiges"
prestige.Parent = leaderstats
local dataFolder = Instance.new("Folder")
dataFolder.Name = player.Name
dataFolder.Parent = serverStorage.RemoteData
local debounce = Instance.new("BoolValue")
debounce.Parent = dataFolder
end)
Module
local module = {}
local replicatedStorage = game:GetService("ReplicatedStorage")
function module.Lift()
replicatedStorage.Remotes.Lift:FireServer()
end
return module
Local Script
local module = require(script.Parent:WaitForChild("ModuleScript"))
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
script.Parent.Activated:Connect(function()
module.Lift()
end)
what is the problem here?

The line local debounce = remoteData[player.Name].Debounce is failing to find the child named "Debounce".
So, looking at how you created the BoolValue in ServerScriptService :
local debounce = Instance.new("BoolValue")
debounce.Parent = dataFolder
You never set the Name property. So there is a BoolValue in the player's folder but it is named "BoolValue", not "Debounce". To fix your error, just add the line to set the Name.
debounce.Name = "Debounce"

Related

Why LeaderStats folder doesn`t creates| Roblox Studio, Lua

My leaderstats script doesnt work for some reason. I dont know why.
When i testing game in roblox studio folder just doesnt creating.
Because of the bug some information doesn`t loads.
There is the code (Script located in ServerScriptStorage):
wait(1)
print("Script LeaderStats started!")
local dataStoreService = game:GetService("DataStoreService")
local clicksDataStore = dataStoreService:GetDataStore("Clicks")
game.Players.PlayerAdded:Connect(function(Player)
local PStats = Instance.new("Folder", Player)
PStats.Name = "PStats"
local clicks = Instance.new("IntValue", PStats)
clicks.Name = "Clicks"
clicks.Value = 0
local playerUserId = "player_"..Player.UserId
-- loading data
local clicksData
local success, errormessage = pcall(function()
clicksData = clicksDataStore:GetAsync(playerUserId, clicksValue)
end)
if success then
clicks.Value = clicksData
end
end)
-- saving data
game.Players.PlayerRemoving:Connect(function(Player)
local playerUserId = "player_"..Player.UserId
local clicksValue = Player.PStats.Clicks.Value
local success, errormessage = pcall(function()
clicksDataStore:SetAsync(playerUserId, clicksValue)
end)
end)
game:BindToClose(function(Player)
for _, Player in pairs(game.Players:GetPlayers()) do
local playerUserId = "player_"..Player.UserId
local clicksValue = Player.PStats.Clicks.Value
local success, errormessage = pcall(function(Player)
clicksDataStore:SetAsync(playerUserId, clicksValue)
end)
end
end)
I tried putting it in workspace, but folder didn`t create.
Make sure it's a Server Script inside of ServerScriptService.
replace line 31 with
clicksData = clicksDataStore:GetAsync(playerUserId)
If you want it to show as a leaderboard, replace line 15 with
PStats.Name = "leaderstats"

leader stats not loading

I am making a clicker game and I need a multiplier value in the leaderstats. it all works until I add the data stores and it stops displaying the multiplier, but the clicks are still being displayed.
Here is my code:
local DSS = game:GetService("DataStoreService")
local ClicksStore = DSS:GetDataStore("ClicksStore")
local MultiStore = DSS:GetDataStore("MultiStore")
game.Players.PlayerAdded:Connect(function(player)
local stats = Instance.new("Folder", player)
stats.Name = "leaderstats"
local clicks = Instance.new("IntValue", stats)
clicks.Name = "Clicks"
clicks.Value = ClicksStore:GetAsync(player.UserId.."--clicks") or 0
local multi = Instance.new("IntValue", stats)
multi.Name = "Multiplier"
multi.Value = MultiStore:GetAsync(player.UserId.."--multi") or 1
game.Players.PlayerRemoving:Connect(function()
ClicksStore:SetAsync(clicks.Value, player.UserId.."--clicks")
MultiStore:SetAsync(multi.Value, player.UserId.."--multi")
end)
while true do
wait(300)
ClicksStore:SetAsync(clicks.Value, player.UserId.."--clicks")
MultiStore:SetAsync(multi.Value, player.UserId.."--multi")
end
end)
Heres a screenshot
problem
You have the key and values backwards in your calls to SetAsync. See the docs.
local clicksKey = player.UserId.."--clicks"
local multiKey = player.UserId.."--multi"
game.Players.PlayerRemoving:Connect(function()
ClicksStore:SetAsync(clicksKey, clicks.Value)
MultiStore:SetAsync(multiKey, multi.Value)
end)
while true do
wait(300)
ClicksStore:SetAsync(clicksKey, clicks.Value)
MultiStore:SetAsync(multiKey, multi.Value)
end

leaderstats not working (Never thought they won't)

So, my leaderstats is not working. It should create a folder inside my player, but it doesn't.
Tried some things to fix, but nothing helped. (This intelligent Ai doesn't want me to post this again)
Here are all of my code in leaderstats:
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local RunService = game:GetService("RunService")
local ServerStorage
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local toolConfig = require(ReplicatedStorage:FindFirstChild("Config"):FindFirstChild("ToolConfig"))
local dataStore = DataStoreService:GetDataStore("Test")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local rebirths = Instance.new("NumberValue")
rebirths.Name = "Rebirths"
rebirths.Parent = leaderstats
local cash = Instance.new("NumberValue")
cash.Name = "Cash"
cash.Parent = leaderstats
local rebirths
local cash
rebirths = dataStore:GetAsync(player.UserId.."_Rebirths")
cash = dataStore:GetAsync(player.UserId.."_Cash")
if rebirths ~= nil then
player.leaderstats.Rebirths.Value = rebirths
end
if cash ~= nil then
player.leaderstats.Cash.Value = cash
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local succes, errormsg = pcall(function()
dataStore:SetAsync(player.UserId.."_Rebirths", player.leaderstats.Rebirths.Value)
dataStore:SetAsync(player.UserId.."_Cash", player.leaderstats.Cash.Value)
end)
if errormsg then
print ("Data error!")
end
end)
1: You forgot to assign serverstorage.
2. Based directly off the code, it seems like the code is on Roblox. You made the mistake of forgetting to check the developer console. That should help.

Attempt to call a nil value when changing an IntValue for leaderstats

I'm trying to make an admin panel, everytime I want to change the value with a username
Code:
leaderstats Script;
--// Set up folder
local AdminModule = require(game:GetService('ServerScriptService').leaderstats.MainModule)
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new('Folder', plr)
leaderstats.Name = 'leaderstats'
local Playtime = Instance.new('IntValue', leaderstats)
Playtime.Name = 'Playtime'
end)
AdminModule.GivePoints('happy_speler', 500)
MainModule:
local module = {
GivePoints = function(plr, amount)
plr:WaitForChild('leaderstats'):WaitForChild('Playtime').Value = amount
end,
}
return module
The error is telling you that you have tried to call a function that doesn't exist.
Looking at the AdminModule.GivePoints function, it looks like it expects a Player object for the plr argument, but you have passed in a string. The string library does not have a WaitForChild function, so calling plr:WaitForChild is throwing the error.
The way to fix this is to properly pass in a Player object :
local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")
local AdminModule = require(ServerScriptService.leaderstats.MainModule)
Players.PlayerAdded:Connect( function(plr)
local leaderstats = Instance.new('Folder', plr)
leaderstats.Name = 'leaderstats'
local Playtime = Instance.new('IntValue', leaderstats)
Playtime.Name = 'Playtime'
if plr.Name == 'happy_speler' then
AdminModule.GivePoints(plr, 500)
end
end)

Attempt to index nil with Position

I'm trying to do something like a spear throw and I'm so confused. It says:
ServerScriptService.FireMagic.FireSpear:16: attempt to index nil with 'Position'
Anyways, here's the LocalScript code:
wait(1)
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Mouse = Player:GetMouse()
local rp = game:GetService("ReplicatedStorage")
local FireSpear = rp:WaitForChild("FireRemote")
local UIS = game:GetService("UserInputService")
local debounce = true
local cd = 10
UIS.InputBegan:Connect(function(input, isTyping)
if isTyping then
return
elseif input.KeyCode == Enum.KeyCode.E and debounce and Character then
debounce = false
FireSpear:FireServer()
wait(cd)
debounce = true
end
end)
and the Script:
wait(1)
local rp = game:GetService("ReplicatedStorage")
local ss = game:GetService("ServerStorage")
local Debris = game:GetService("Debris")
local ssFireSpear = ss.FireMagic:WaitForChild("ssFireSpear")
local FireRemote = rp:WaitForChild("FireRemote")
local UhTable = {}
local function LookatMouse(Mouse, RootPart)
local bodyG = Instance.new("BodyGyro")
bodyG.MaxTorque = Vector3.new(0, 500000, 0)
bodyG.P = 10000
bodyG.CFrame = CFrame.new(RootPart.Position, Mouse.Position)
bodyG.Parent = RootPart
Debris:AddItem(bodyG, 1)
end
local function MoveTowardsMouse(Mouse, Main)
local bodyV = Instance.new("BodyVelocity")
bodyV.MaxForce = Vector3.new(500000, 500000, 500000)
bodyV.Velocity = CFrame.new(Main.Position, Mouse.Position).LookVector * 100
bodyV.Parent = Main
local bodyG = Instance.new("BodyGyro")
bodyG.MaxTorque = Vector3.new(500000, 500000, 500000)
bodyG.P = 10000
bodyG.CFrame = CFrame.new(Main.Position, Mouse.Position)
bodyG.Parent = Main
end
FireRemote.OnServerEvent:Connect(function(Player, Mouse_CFrame)
if UhTable[Player.Name] == true then
return
end
UhTable[Player.Name] = true
local Character = Player.Character
local RootPart = Character:WaitForChild("HumanoidRootPart")
local folder = workspace:FindFirstChild("DebrisFolder") or Instance.new("Folder",workspace)
folder.Name = "DebrisFolder"
local RightHand = Character:WaitForChild("RightHand")
local FireSpear = ssFireSpear:Clone()
local Handle = FireSpear:WaitForChild("Handle")
local Hitbox = FireSpear:WaitForChild("Hitbox")
local Mesh = FireSpear:WaitForChild("Mesh")
FireSpear:SetPrimaryPartCFrame(RightHand.CFrame)
FireSpear.Parent = folder
local weld = Instance.new("Motor6D")
weld.Parent = Handle
weld.Part0 = RightHand
weld.Part1 = Handle
Hitbox:SetNetworkOwner(nil)
local function MakeStuffHappen()
spawn(function()
LookatMouse(Mouse_CFrame,RootPart)
wait(.6)
weld:Destroy()
MoveTowardsMouse(Mouse_CFrame,Hitbox)
end)
end
MakeStuffHappen()
end)
I'm following a tutorial but I don't know how the issue got there.
Your error is pointing to the fact that you are trying to reference fields on an object that doesn't exist. In this case, it's the ´Mouse´ object, which you never supplied from the client.
To fix this, pass the mouse information in when you call the RemoteEvent's FireServer() function.
UIS.InputBegan:Connect(function(input, isTyping)
if isTyping then
return
elseif input.KeyCode == Enum.KeyCode.E and debounce and Character then
debounce = false
local mouseCFrame = Mouse.Hit
FireSpear:FireServer(mouseCFrame)
wait(cd)
debounce = true
end
end)

Resources