I was creating a piece of code to attempt to crack into a program that I created, but it keeps printing out “1” instead of adding 1 to the value every time. How can I prevent this from happening?
local breakpin = 0
repeat
local breakpin = 1 + breakpin
print(breakpin)
if breakpin == pin then
success = true
end
until success == true
Related
i was trying to make random spawns but sometimes, it gives me an error attempt to index nil with 'CFrame' when i enter the portal.
Here is the code
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild('Humanoid') and not db and not hit.Parent.Parent:IsA("Tool") then
db = true
local spawns = workspace.Spawns
local spawnPoint = math.random(1,13)
local plr = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
local ss = game:GetService("ServerStorage")
plr.InLobby.Value = false
if UIS.TouchEnabled == true then
script.Ability:Clone().Parent = plr.PlayerGui
end
if not plr.Backpack:FindFirstChild(plr.leaderstats.Glove.Value) and plr.leaderstats.Glove.Value ~= "edgelord" or plr.leaderstats.Glove.Value ~= "ḇ̵̰̪̙̭̎̓o̴̰͈͊̈̓̓̕b̶̨̀͐͌͑͒" then
if ss:FindFirstChild(plr.leaderstats.Glove.Value) then
ss:FindFirstChild(plr.leaderstats.Glove.Value):Clone().Parent = plr.Backpack
hit.Parent.HumanoidRootPart.CFrame = spawns:FindFirstChild(spawnPoint).CFrame
wait(2)
db = false
end
end
end
end)
The "attempt to index nil" error is always telling you that the object you're trying to get a value out of doesn't exist.
In this case, it's probably spawns:FindFirstChild(spawnPoint) that doesn't exist. The FindFirstChild searches the names of the children, and you are passing in a number between 1 - 13. This makes an assumption about the names of the children that is unnecessary and is likely the source of your error.
A safer way to access these objects is to simply get all of the spawn points as an array, and then access a random index within that array.
local spawns = workspace.Spawns:GetChildren()
local randomIndex = math.random(1, #spawns)
local targetCFrame = spawns[randomIndex].CFrame
hit.Parent.HumanoidRootPart.CFrame = targetCFrame
while true do
wait(1)
local randomnumber = math.random(18,150)
local x = math.random(1,50)
local Pointgiver = game.ReplicatedStorage.Points:Clone()
Pointgiver.Parent = game.Workspace
Pointgiver.Position = Vector3.new(randomnumber,0.5,x)
Pointgiver.Transparency = 0
end
local pointgiver = game.Workspace:WaitForChild("Points")
pointgiver.ClickDetector.Mousetouch:Connect(function()
pointgiver:Destroy()
end)
as you see, im using a waitforchild function which waits for a part to spawn and doesnt give errors thats like "There is no part named "Points" "
but it wont destroy it, sorry if that didnt make sense
ClickDetector has no function named Mousetouch, instead, you should be using MouseClick which fires whenever the player clicks the respective Part. Also your code which listens for the ClickDetector.MouseClick is after the while loop and as such, it will never run as you keep calling the while loop repeatedly, and never break out of it.
while true do
task.wait(1)
local randomnumber = math.random(18,150)
local x = math.random(1,50)
local Pointgiver = game.ReplicatedStorage.Points:Clone()
Pointgiver.Position = Vector3.new(randomnumber,0.5,x)
Pointgiver.Transparency = 0
PointGiver.ClickDetector.MouseClick:Connect(function()
PointGiver:Destroy()
end)
Pointgiver.Parent = game.Workspace
end
local MaxClicks = 50
if game.Players.LocalPlayer.leaderstats.Clicks.Value == MaxClicks then
script.Parent.Parent.Visible = true
end
The reason why when you get to 50 clicks you see no changes is because your if statement is only run once. If you want to check every time the Clicks value is changed you can use:
local MaxClicks = 50
game.Players.LocalPlayer.leaderstats.Clicks.Changed:Connect(function()
if game.Players.LocalPlayer.leaderstats.Clicks.Value == MaxClicks then
script.Parent.Parent.Visible = true
end
end)
My goal here is to send the player object and the object name through to the client script to display the object name on a text label.
When I run this, it prints nil and nil. I want player.Name and name as you will see in the second code sample. Another error I get is "attempt to concatenate nil with string" from the client script.
Here is my server-side code:
script.onTouch.OnInvoke = function(button, sellObj, sellObjValue, buyObj, buyObjValue, afterWave, isLoadedPart)
if isLoadedPart == true then
local info = script.Parent.Parent.info
local player = info.player.Value
local owner = info.owner.Value
local savedItems = info.savedItems.Value
local builds = script.Parent.Parent.activeBuilds
if afterWave > info.activeWave.Value then
info.activeWave.Value = afterWave
end
button.Parent = savedItems.buttons
button.jobDone.Value = true
if sellObj ~= nil then
sellObj.Parent = savedItems.builds
end
if buyObj ~= nil then
buyObj.Parent = builds
end
local td = require(script.Parent.tycoonDictionary)
if not table.find(td.boughtButtons, button.objectId.Value) then
table.insert(td.boughtButtons, button.objectId.Value)
end
local ui = game.ReplicatedStorage:FindFirstChild('onPartLoad')
if ui then
ui:FireClient(player, 'buyObj.Name')
print('yes')
else
print('no')
end
else
local info = script.Parent.Parent.info
local player = info.player.Value
local owner = info.owner.Value
local money = info.player.Value.leaderstats.Money
local savedItems = info.savedItems.Value
local builds = script.Parent.Parent.activeBuilds
if money.Value >= buyObjValue or money.Value == buyObjValue then
if afterWave > info.activeWave.Value then
info.activeWave.Value = afterWave
end
button.Parent = savedItems.buttons
button.jobDone.Value = true
if sellObj ~= nil then
sellObj.Parent = savedItems.builds
money.Value += sellObjValue
end
if buyObj ~= nil then
buyObj.Parent = builds
money.Value -= buyObjValue
end
local td = require(script.Parent.tycoonDictionary)
if not table.find(td.boughtButtons, button.objectId.Value) then
table.insert(td.boughtButtons, button.objectId.Value)
warn(td.boughtButtons)
end
else
player.PlayerGui.inGame.error.label.invokeScript.errorInvoke:Invoke("Insufficient Funds")
end
end
script.Parent.waveChecker.afterRun:Invoke()
end
And here is my client-side code:
game.ReplicatedStorage.onPartLoad.OnClientEvent:Connect(function(player, name)
print(player.Name, name)
print(script.Parent.Text)
script.Parent.Text = name .. 'is loaded.'
print(script.Parent.Text)
end)
Here I will tell you a little about this game. It is a tycoon that saves data using a table with all button Ids in it. When it loads, it gets the button associated with the id and fires the server code for every button. If the button is a load button, it fires the client with the player and the buyObj.Name.
Is there just a little mistake or can I not send arguments to the client at all? Any help will be appreciated!
The OnInvoke callback's first argument is always the player that fired it, so you should change line 1 of the first script to:
script.onTouch.OnInvoke = function(playerFired, button, sellObj, sellObjValue, buyObj, buyObjValue, afterWave, isLoadedPart)
And :FireClient() requires a player argument as its first argument, so you should change
ui:FireClient(player, 'buyObj.Name')
to
ui:FireClient(playerFired, player, 'buyObj.Name')
Here is the solution I came up with;
First, I read through some Roblox documentation to find that the first argument I had to send when using :FireClient was the player, and because I already had the player there, it was just sending the function to that player. Now, I had 2 choices, I could send the player twice, or delete the player variable from the script. I chose the second one.
Here is what the :FireClient line in the server script looks like now:
game.ReplicatedStorage:WaitForChild('onPartLoad'):FireClient(player, buyObj.Name)
And here is what the client function script looks like now:
game.ReplicatedStorage.onPartLoad.OnClientEvent:Connect(function(name)
if name ~= 'starterFoundation' then
script.Parent.Text = name .. ' is loaded.'
end
end)
Thank you #TypeChecked for helping me realize this!
local level = 3 -- Required access level
local sideIn = "bottom" -- Keycard Input Side
local sideOut = "right" -- Redstone output side
local rsTime = 3 -- Redstone time
while true do
if disk.isPresent(sideIn) then
term.clear()
term.setCursorPos(1,1)
local code = fs.open("disk/passcode.lua", "r").readAll()
if code == nil then
local code = 0
else
local code = tonumber(code)
end
if code >= level then
print("> Access Granted")
disk.eject(sideIn)
rs.setOutput(sideOut,true)
sleep(rsTime)
rs.setOutput(sideOut,false)
else
print("> Permission Denied")
disk.eject(sideIn)
end
end
end
When there's no disk inserted, it throws an error:
.temp:15: attempt to compare string with number expected, got string
Does anyone know how to fix this issue? I throwed in a nil checker but it seems to not work. Any ideas on how could I fix this? I've been trying for at least half an hour now, and I still have no clue.
In this section:
local code = fs.open("disk/passcode.lua", "r").readAll() --(1)
if code == nil then
local code = 0 --(2)
else
local code = tonumber(code) --(3)
end
It first makes a new local variable with local code = .... In the new block that you create with the if, you also create new local variables with local code = .... Since it has the same name as the local before it, it "masks" it, prohibiting you from accessing the first code in the rest of the block. The value that you assign 0 to is not the same variable outside the if, so the first code is unaffected. At else the block for the second code ends and the same thing happens between else and end when the condition is false. To not assign the values 0 or tonumber(code) to new variables, you have to remove the local from local code = .... So the following is what it should be:
local level = 3 -- Required access level
local sideIn = "bottom" -- Keycard Input Side
local sideOut = "right" -- Redstone output side
local rsTime = 3 -- Redstone time
while true do
if disk.isPresent(sideIn) then
term.clear()
term.setCursorPos(1,1)
local code = fs.open("disk/passcode.lua", "r").readAll()
if code == nil then
code = 0
else
code = tonumber(code)
end
if code >= level then
print("> Access Granted")
disk.eject(sideIn)
rs.setOutput(sideOut,true)
sleep(rsTime)
rs.setOutput(sideOut,false)
else
print("> Permission Denied")
disk.eject(sideIn)
end
end
end