#Script ignoring the loop, gives only 1 item instead of desired quantity
1 messages · Page 1 of 1 (latest)
can you print out the qunum variable and amountloop variable before the loop?
maybe
for i = 1, qnum do
-- code here
end
also why you doing code on the client for purchasing things
use a remote event to the server to check if plr has enough money for the transaction and then clone stuff on the server
cause if you do it on a local script, only you (the client) will see it
i'll try that
convienence
alright
mb
nah its ok
shitty wifi
im aware
i'll paste the entire code into a server side script
except the button:connect bit
yeah but tey to fix ur bug first
try
I suggested a for loop which will loop till it reaches the max provided index
that being qnum
bad idea
i'll just cut out the clone bits
problem is i dont know what to use as a fire
or something
alright
so like this?
create a remote event somewhere in replicated storage, and the on a Script, use RemotEvent.OnServerEven:Connect(function(player,data)
-- code here
end)
alright
im making it into a remotefunction instead of a remote event
alr
you connect remote functions differently so:
RemoteFunction.OnServerInvoke = function(plr,data)
end
so like thi
or
alr
** You are now Level 8! **
no
oh so i do local function?
proxy.OnServerInvoke = function(player,productClone)
return "Successfully bought item " .. productClone.Name
end
for remote functions u need to return
@dull mauve
wait is that it
oh wait
yes
really
yes
huh
proxy.OnServerInvoke = function(player,productClone)
return "Successfully bought item " .. productClone.Name
end
you then just need to add the rest of code
i was just showing how to connect the onserverinvoke @dull mauve
oh
lmao
mb
also
indexing nil with :clone()
don't clone the product 2 times, u can just send the tool
im presuming the serverside script isnt reading productclone as a instance
yh cuz u cloned it 2 times
u don't need to clone it anymore on the client
can u send output
use invoke with the product, u don't need productclone anymore
hmmmm maybe instead of doing a for loop on the client
we can invoke the server the amount of products we want to clone
so
.OnServerInvoke = function(plr,product,amount)
alright
its still not reading product as an instance
it can
weirdly the second time I buy the product
it comes up with an error
r u not doing
local newtool = tool:Clone()
and just doing tool:Clone() on the server
and it's just removing the tool entirely
yeah im not
i'll do local
like
that should be the solution prolly
local newtool = tool:Clone()
yep
@dull mauve make sure you're doing the currency math on the server
im not
sob
but the leaderstats are serversided
not that
oh
the shop one
on the client u can send the item values
and on the server u can do a for loop
to then clone in player if has enough MONEY for the items
this local script does the math calculating
hmm i can do a if statement
oh
tools
so do i move the if statement to the server?
yeah
alright
yeah but place the return statement at the end at if the player has the cash
yeah i did
okay they now cost $1
but it says $15
though if u get the due from startergui
it will get the default value
you should maybe have a uhhhhhh
values of all the items cost in replicated storage
wait
set attributes on the tools
wdym
right
And then set a price attribute
done
then get the price times the amount
is this in the local script
** You are now Level 9! **
or the serverside
Server side
right
im guessing like this
get the cash by productclone:GetAttribute("Price")
oh okay
and paste the productclone.parent when the player has enough money
i never really fiddled with attributes
also do a for loop for the amount
for i=1, amount do end
then clone it and parent it to the player backpack @dull mauve
so like this?
set the cash BEFORE the for loop
wdym
and after the loop then return successfully purchased
OH
ah okay
alright is this better?
i think its the for i = 1 loop
in the local script
so i removed that
still nothing
oh ur not sending the amount
the amount player wanna buy
invoke server with tool and amount of it
send img
send the server script
show me it
the script
send the qnum
oh so qnum is a number
try to do
yep
Tonumber() all of it
no it doesnt get the tool on the second time someone buys it
fixed it by adding :Clone() to product
still?
no you need to clone it in the for loop
yeah
so what do i remove local productclone = product**:Clone()**
(the bold text)
you could remove it entirely
and then use it in the for loop
I cant
wym
yeah you did
but then ruined it i guess but whatever
We'll continue in the next hour
@dull mauve did you manage to fix it
nope
What's the problem now
okay nevermind
you fixed it?
yep