#Bug problem
1 messages · Page 1 of 1 (latest)
local part = script.Parent
part.Touched:Connect(function(touch)
local plr = game.Players:GetPlayerFromCharacter(touch.Parent)
local leaderstats = plr:FindFirstChild("leaderstats")
if leaderstats then
local coins = leaderstats:FindFirstChild("Coins")
local clicks = leaderstats:FindFirstChild("Clicks")
coins.Value += clicks.Value
clicks.Value = 0
end
end)
why sometimes line 4 send me problem
sometimes not everytime
sometimes the part can be touched by something that is not a player
then game.Players:GetPlayerFromCharacter(touch.Parent) returns nil
yes this happen
and plr:FindFirstChild("leaderstats") errors
you can fix this by adding a guard clause after line 3
if not plr then return end
it exits the function if a player isnt found
what do you mean
but like this there will not be any problem on game right ?
@agile dagger
what u mean ?
your way works fine but you can just use the fix i said
can i add like if plr then and add everything start from line 5 and else then print ("wrong" )
yeah
but this does the same thing
ok but better return right ?
okk but what return mean Y_Y
return exits a function
;compile
local function A()
print("Hello World!")
return
print("This won't print")
end
A()
print("a")
Hello World!
This won't print
a
what
;compile
local function foo()
print("Hello World!")
return 3
print("This won't print")
end
foo()
print("a")
/opt/wandbox/lua-5.4.7/bin/lua: prog.lua:6: 'end' expected (to close 'function' at line 1) near 'print'
ohhh
;compile
local function A()
print("Hello World!")
return;
print("This won't print")
end
A()
print("a")
/opt/wandbox/lua-5.4.7/bin/lua: prog.lua:6: 'end' expected (to close 'function' at line 1) near 'print'
oh okk
local part = script.Parent
part.Touched:Connect(function(touch)
local plr = game.Players:GetPlayerFromCharacter(touch.Parent)
local leaderstats = plr:FindFirstChild("leaderstats")
if plr then
if leaderstats then
local coins = leaderstats:FindFirstChild("Coins")
local clicks = leaderstats:FindFirstChild("Clicks")
coins.Value += clicks.Value
clicks.Value = 0
end
end
else
end)
there is problem in else
oh i put else in wrong place
tysmmmm it worked
local part = script.Parent
part.Touched:Connect(function(touch)
local plr = game.Players:GetPlayerFromCharacter(touch.Parent)
if plr then
local leaderstats = plr:FindFirstChild("leaderstats")
if leaderstats then
local coins = leaderstats:FindFirstChild("Coins")
local clicks = leaderstats:FindFirstChild("Clicks")
coins.Value += clicks.Value
clicks.Value = 0
end
else
return
end
end)
here ty very much
well you don't even need the return there
because you put eveyrthing in the if statement
ok
like if i want player to touch somoething and tp to it i will do untill if plr then
then how i reach to humanoid part of plr
like if click on button or touch something
@agile dagger
what do you mean
** You are now Level 8! **
what you're saying is confusing
like what exactly are you asking
reword it perhaps
I just figure it out but i have doffrante problem 😦
ok then what is it
describe it in a way that makes sense
I wouldn't rely on using chatgpt too much if you can't properly understand the code it writes
because it can make mistakes and you wouldn't be able to figure out the mistake since you can't figure out how the code works exactly
i learn every thing from chatgpt its awesome ai
yeah happen alot also lol
but i just use it as fast respond and if it got it wrong i come ask here
@fossil bone u know rebirth calculation and like this
you mean like simulator rebirths?
like i did intvalue in replicated storge that i put value of it 1 so every click it gives 1
but i want each rebirth increase makes click value in replicated storge increase 10%
like if it gives 1 per click next gives 1.1 , and when uget 2 rebirth it increase 1.1 by 10%
u understand ?
ok then what you'd want to do is for every click the user doed
define a variable for their amount of rebirths
then do something like this
wait
do you want it to be only whole numbers
or include decimals
decimals
ok then
what you'll wanna do is
first define the amount of rebirths they have
then do
i want math calculation to see rebirth value like
click value =rebirth +0.5 *3
for example
ok so we have their rebirths
you'd need to do something like the multiplication value
make that
0.1*(1^#rebirths)
then you have that value defined
what is # ?
multiplication = 0.1*(1^#rebirths)
then do
1 + multiplication
then you have your clicks
it's just an abbriviation
for number
meaning the number of rebirths the player currently has
uamm thatss too much i just want i create script in server service that every time check rebirth value and
make calculation click value = rebirthvalue *2
for example
i only need the calculation click value = rebirthvalue * + what
soo rebirth gives 10% more click value each time i increase
#rebirth ?
can i delete it ?
here what i mean
finalClickValue = baseClickValue * (1.1 ^ rebirths)
chat gpt did it its right ?
well that's exactly what I did
what I came up with is 1 + 1(1.1^1)-1
the first 1 is the base click value
assuming you it never gets increased
otherwise simply just do
ohh okk but can u tell me how u got this calculation lol
u know it or do it steps ?
this is what you want to use for the rebirth addition
I purely did it in my head
what
baseclickvalue + baseclickvalue(1.1^#rebirths)-baseclickvalue
that's what you want to do for just the rebirth multiplication
if you want it to be the final calculation from the get go just do baseclickvalue + baseclickvalue(1.1^#rebirths)
okk tysm
if you provide a script for me I can perhaps give you an example
but script doesnt work
just show it to me
game.Players.PlayerAdded:Connect(function(plr)
while wait() do
local click_value = game.ReplicatedStorage.Click_Value.Value
local leaderstats = plr:WaitForChild("leaderstats")
if leaderstats then
local rebirth = leaderstats:FindFirstChild("Rebirth")
if rebirth then
local newClickValue = click_value * (1.1 ^ rebirth.Value)
click_value = newClickValue
end
end
end
end)
doesnt change click value
nope just doesnt change click value
doesnt change
** You are now Level 16! **
does your player have 0 rebirths
1
ohh i understand why maybe
i should add first line click value = 1
@fossil bone nothing work
I'm looking at the script rn
hold on
that's strange because looking at the script i assume it would work
one question
yes but doesnt change click value
is the value inside replicated storage a intvalue
or a number value
like the instance type
intvalue
does it like only add one?
with no multiplication?
what u mean ?
oh
and replace it with a number value
int value only take whole numbers
no decimals
number values take decimals
ohhh that something new
just replace it as a numbervalue and rename it
okk tysm
now it doesnt even click
ok what now
so its at rebrith 1 still gives 1 not 1.1
that is actually so weird
show me your updated code
this would be so much easier for me to fix if I was actually on pc lol
oh for sure
game.Players.PlayerAdded:Connect(function(plr)
while wait() do
local click_value = game.ReplicatedStorage.Click_Value.Value
local leaderstats = plr:WaitForChild("leaderstats")
if leaderstats then
local rebirth = leaderstats:FindFirstChild("Rebirth")
if rebirth then
local newClickValue = click_value * (1.1 ^ rebirth.Value)
click_value = newClickValue
end
end
end
end)
and now click_value is numbervallue not int value
you something I'm starting to realize
local click_value = game.ReplicatedStorage.Click_Value.Value
``` i think bec this line in while true
is that this script is only defining the value of the clicks once
can you show me the code for the button that you use to clicj
or whatever
yes just show me the script for clicking
like this script seems formatted so weirdly
okk
yeah
but remote event
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local click_value = game.ReplicatedStorage.Click_Value.Value
local bag = game.ReplicatedStorage.BagValue.Value
local bag_value = bag -1
local click_event = game.ReplicatedStorage.Click
mouse.Button1Down:Connect(function(click)
local leaderstats = plr:FindFirstChild("leaderstats")
if leaderstats then
local clicks = leaderstats:FindFirstChild("Clicks")
if clicks then
if clicks.Value <= bag_value then
click_event:FireServer()
end
end
end
end)
in starter player script
ok so what's the script for the clickevent
you fire an event to the server correct
you'd have a script somewhere respond to it
local click_event = game.ReplicatedStorage.Click
local click_value = game.ReplicatedStorage.Click_Value.Value
click_event.OnServerEvent:Connect(function(plr)
local leaderstats = plr:FindFirstChild("leaderstats")
if leaderstats then
local clicks = leaderstats:FindFirstChild("Clicks")
if clicks then
clicks.Value += click_value
end
end
end)
htere is serverscript service
if you have this script then
whats the purpose of this script?
bec clint to server for data save
let me redo this script for you
what do u mean ?
bec this script is local and i want it to server for data save
np take your time
what thing maybe i can do it too
no no let me do it
you might not get what I mean
it's just a pain in the ass to code on mobile
replace this script
with this
local click_event = game.ReplicatedStorage.Click
click_event.OnServerEvent:Connect(function(plr)
local click_value = game.ReplicatedStorage.Click_Value.Value
local leaderstats = plr:FindFirstChild("leaderstats")
if leaderstats then
local clicks = leaderstats:FindFirstChild("Clicks")
if clicks then
clicks.Value += click_value
local rebirth = leaderstats:FindFirstChild("Rebirth")
if rebirth then
click_value = click_value*(1.1^rebirth.Value)
end
end
end
end)
see if that works
if it doesn't then you'll need to wait till I get home to help you because using mobile to code is literal asscheeks
replace it with exactly this
like the server event script
still 1 click value
and you have 1 rebirth?
2
hmmm
I guess I'll just wait till I get home to help you
because mobile is absolutely atrocious to code
no don't the solution is actually really simple
I can fix it
all chatgpt will do is make the problem worse probably
trust me i know because I've used chatgpt before to help and it can make things worse
oh ok
local click_event = game.ReplicatedStorage.Click
click_event.OnServerEvent:Connect(function(plr)
local click_value = game.ReplicatedStorage.Click_Value.Value
local leaderstats = plr:FindFirstChild("leaderstats")
if leaderstats then
local clicks = leaderstats:FindFirstChild("Clicks")
local rebirth = leaderstats:FindFirstChild("Rebirth")
if clicks and rebirth then
click_value = click_value*(1.1^rebirth.Value)
clicks.Value += click_value
end
end
end)
here what i did but still problem there
@fossil bone nvm i will just delete rebirth
when I get home I'll just make my own system from scratch to see if I can fix the problem
no no i will just delete it
this problem seems so stupidly simple
it's probably just some small thing you don't notice that's causing it to not work
yeah i know but i do alot of things wrong or maybe wrong place soo i will just delete all and do it later