#Script ignoring the loop, gives only 1 item instead of desired quantity

1 messages · Page 1 of 1 (latest)

dull mauve
#

Player press purchase button > player recieves 1 item, if they didnt press the up or down arrows the price is 1 even though its supposed to be 15, it gives 1 item instead of giving the desired quantity.

#

loop at lines 34 to 40

spiral flume
grave moon
#

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

grave moon
#

yummy double ping

#

triple*

dull mauve
#

mb

grave moon
#

nah its ok

dull mauve
#

shitty wifi

dull mauve
#

i'll paste the entire code into a server side script

#

except the button:connect bit

grave moon
#

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

dull mauve
#

i'll just cut out the clone bits

dull mauve
#

or something

grave moon
grave moon
#

value

dull mauve
dull mauve
grave moon
#

alr

grave moon
dull mauve
#

yeah

#

that was my intention

grave moon
#

yeah remove the ")" at the end

#

idk

dull mauve
#

for the button:connect

grave moon
#

then whys the buystock underlined

#

wth red

dull mauve
#

fixed it tho

grave moon
#

alr

digital ospreyBOT
#

studio** You are now Level 8! **studio

dull mauve
#

is this correct?

grave moon
dull mauve
#

oh so i do local function?

grave moon
#

proxy.OnServerInvoke = function(player,productClone)

return "Successfully bought item " .. productClone.Name
end

#

for remote functions u need to return

#

@dull mauve

dull mauve
#

yeah ik

#

ive seen

grave moon
dull mauve
grave moon
#

yes

dull mauve
#

huh

grave moon
#
proxy.OnServerInvoke = function(player,productClone)

 

return "Successfully bought item " .. productClone.Name
end

dull mauve
#

thought i was gonna have to add productclone:Clone()

#

in the serverside script

grave moon
#

i was just showing how to connect the onserverinvoke @dull mauve

grave moon
#

also

dull mauve
grave moon
dull mauve
#

im presuming the serverside script isnt reading productclone as a instance

grave moon
dull mauve
#

so this is once

grave moon
#

u don't need to clone it anymore on the client

dull mauve
#

right

#

i see

grave moon
#

you can just provide the product and the server will clone it

#

if money

dull mauve
#

okay so it fixed the problem... kind of

#

didnt really give me the desired quantity

grave moon
#

can u send output

dull mauve
#

oh and same error

#

when buying twice

dull mauve
grave moon
#

check line 30

#

of local script

dull mauve
#

thats invoking the server

#

wait cant i move productclone

grave moon
# dull mauve

use invoke with the product, u don't need productclone anymore

dull mauve
#

yeah i was thinking of that

#

still isnt giving me the desired quantity

grave moon
#

hmmmm maybe instead of doing a for loop on the client

dull mauve
#

also same issure

grave moon
#

we can invoke the server the amount of products we want to clone

#

so

#

.OnServerInvoke = function(plr,product,amount)

dull mauve
#

its still not reading product as an instance

grave moon
#

is it a tool

#

ur sending

#

@dull mauve

dull mauve
#

it is

grave moon
#

can it find the product

#

Try printing the product

dull mauve
#

weirdly the second time I buy the product

#

it comes up with an error

grave moon
#

r u not doing
local newtool = tool:Clone()

#

and just doing tool:Clone() on the server

#

and it's just removing the tool entirely

dull mauve
#

i'll do local

#

like

grave moon
#

that should be the solution prolly

dull mauve
#

local newtool = tool:Clone()

dull mauve
#

OH IT FIXED IT

grave moon
#

yep

dull mauve
#

LES GOOOO

#

finally

#

a modular shop system

grave moon
#

@dull mauve make sure you're doing the currency math on the server

dull mauve
#

sob

#

but the leaderstats are serversided

grave moon
#

can u show the serverscript

#

rq

dull mauve
dull mauve
#

the leaderstats one

#

or

grave moon
dull mauve
#

oh

grave moon
dull mauve
grave moon
#

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

dull mauve
#

this local script does the math calculating

dull mauve
grave moon
#

well if u get a hacker

#

he can maybe exploit it

#

and get infinite toolz

dull mauve
grave moon
#

tools

dull mauve
#

so do i move the if statement to the server?

grave moon
#

yeah

dull mauve
dull mauve
#

like this?

grave moon
dull mauve
#

yeah i did

dull mauve
#

but it says $15

grave moon
#

it will get the default value

dull mauve
#

huh

#

do i send a

#

actually no im doing the serverinvoke

grave moon
#

you should maybe have a uhhhhhh

#

values of all the items cost in replicated storage

#

wait

#

set attributes on the tools

dull mauve
#

wdym

grave moon
#

Price: 1 (number)

#

go to ur tools

dull mauve
#

right

grave moon
#

And then set a price attribute

dull mauve
#

done

grave moon
#

then get the price times the amount

dull mauve
#

is this in the local script

digital ospreyBOT
#

studio** You are now Level 9! **studio

dull mauve
#

or the serverside

grave moon
#

Server side

dull mauve
#

right

dull mauve
grave moon
dull mauve
#

oh okay

grave moon
#

and paste the productclone.parent when the player has enough money

dull mauve
#

i never really fiddled with attributes

grave moon
#

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

grave moon
dull mauve
grave moon
#

and after the loop then return successfully purchased

dull mauve
#

OH

dull mauve
grave moon
#

Yep

#

and at the bottom if there's not enough cash

#

Return "not enough cash"

dull mauve
#

i think its the for i = 1 loop

#

in the local script

#

so i removed that

#

still nothing

grave moon
#

uhhhhhhhh

#

try printing the price and players cash @dull mauve

grave moon
dull mauve
#

wdym by amount

grave moon
#

invoke server with tool and amount of it

dull mauve
#

oh

#

oh wait

#

there we go

#

anddd

#

nope

grave moon
#

which line

#

did it error

dull mauve
#

29

#

same issue

grave moon
#

send img

dull mauve
#

just me being an idiot on accident

#

still nothing?

grave moon
dull mauve
grave moon
#

bru ur sending a number

#

no need for .value

dull mauve
#

oh

#

still the same error

#

on the local script

grave moon
#

show me it

dull mauve
grave moon
#

the script

grave moon
#

@dull mauve

grave moon
dull mauve
#

so which one do i put, amount or qnum

grave moon
#

try qnum

#

@dull mauve

dull mauve
grave moon
dull mauve
#

i think its beacuse of the

#

moneydue

grave moon
#

try to do

dull mauve
#

yep

grave moon
#

Tonumber() all of it

dull mauve
#

it was the moneydue

grave moon
#

now it doesn't get the tool

#

huh

dull mauve
dull mauve
#

but still not giving the desired quantity

dull mauve
grave moon
grave moon
dull mauve
dull mauve
#

(the bold text)

grave moon
grave moon
#

wym

dull mauve
#

oh wait i can set

#

moneydue to product

#

anyways I gtg i'll be back in an hour or so

grave moon
#

Alr

#

hope i helped

dull mauve
#

yeah you did

#

but then ruined it i guess but whatever

#

We'll continue in the next hour

dull mauve
#

@grave moon

#

im back

grave moon
#

@dull mauve did you manage to fix it

dull mauve
#

nope

grave moon
#

What's the problem now

dull mauve
#

okay nevermind

grave moon
#

you fixed it?

dull mauve
#

yep

dull mauve
#

@grave moon

#

getting the same issue

dull mauve
#

but i dont know whats causing it

#

oh i see the issue