#Can someone explain to me why this doesnt work
1 messages · Page 1 of 1 (latest)
It might be the player loading back in before the RemoteEvent is called to the server
you need to check if the player loaded if not wait
player.CharacterAdded:Wait()
remotepassave:FireClient(player, x5booleansave)```
also you're connecting it multiple times
which causes repeated fires to the client and memory leaks (lag)
@karmic sonnet
i'm really confused on what you're tryna do here honestly.
I can help you rewrite the code but i need to know when and what for you're calling the server
so "x5" is a boolean sent from the client to the server indicating that the thing that what something equals true over on the client (which by default equals false) so it sends true over to the server so the server can save it and return it when the player leaves and joins back the game (which works fine) or when the player dies (which completely breaks everything to the point button.mouseclick1 doesnt work anymore and it should
yo i think i legit just solved why soemthing is broke explaing it to u
how would I fix this?
If you're trying to return it back
use remotefunctions
connecting only once
i was told never to use remotefunctions
connecting what multiple times?
I see you're trying to return the same value as a confirmation the value
Remote event is like throwing a rock
remote function throwing a rock and they throw the same rock at you (in your case) or a different one
that can contain differen args
characteradded:connect()
do playeradded then character added
under character added fire the client with the args as a remote function
so lua local coolevent = remotefunction:InvokeServer(bool)
this on the client
on the server
i did that before and it didnt work but ill try it again cuz i fixed the problem i was having so this will prob work now
so i did that and it worked but maybe i put it in the wrong spot tho or sum
local cooleventonserver = --path to it
cooleventonserver.OnServerInvoke = function(player, bool)
player.Character or player.CharacterAdded:Wait()
return bool
end)
``` if you want to use remotefunc
really just start by using remote functions
the error you're getting is because you're setting the data too fast many times
cache the data and save it when the player leaves
that's normal 
im getting red lines under "player.character or "
wHeRe Do I pUt ThAt
fetch from datastore once, only one time, shouldn't need to fetch it again. store changes in a table, save periodically (once every ~5mins or so) and on playerremoving and game:bindtoclose. you're getting the throttling error because you're using datastores inappropriately like every time the player presses jump you call datastore:setasync that will get you throttled 👍
in fact if you want to work with datastores it may be easier for you to just use profilestore
it does all the difficult work like saving and loading and catching errors for you, all you have to care about is what data goes into the profile and reading it the first time, profilestore generally does the rest
im only fetching from datastore when player leave and join game (I tested that to see if it would work or not)
When you do charcter added you're also getting when the player respawns
ye ik, i deleted the characteradded below the playeradded so it wont do that anymore
but i am still getting the error even though its gone and I wasnt getting any befroe
this one
can you send both client and server
you are doing a cyclic firing
player joins > server fires client > client fires server > server fires client and goes on
it doesnt look cyclic but it is creating infinite connections
but it might be cyclic because the remotes the variables are actually connected to aren't shown
first of all remove that connection
it doesnt cycle
the infinite connections is bigger problem tho
what connection?
characteradded in the server
anyway i think i've gotten lost a bit somewhere, are you having a different problem now or something? what are you trying to do exactly
and this doesn't make sense
the code works now but i dont want a huge memory leak soooo
infinite connections is fairly easily avoided by connecting to events only once instead of multiple times or in your case, when the client fires an event
im being 100% honest
yeah when they die the boolean that turned true after they bought it goes to false so i want it to be true again and it works but i dont want a memory leak
** You are now Level 13! **
** You are now Level 6! **
how do i put player.characteradded somewhere else in the script?
take this: lua remote.OnServerEvent:Connect(function(player) player.CharacterAdded:Connect(...stuff here...) end)
and then just imagine what happens when a client does this:
for i=1,100 do
remote:FireServer()
end``` you should be able to tell us what the problem here is
how many times does this code connect to player.CharacterAdded?
try making him do
the same thing
but instead it just prints
spawned
he is currently doing the same thing
100?
yeah js to make him understand
yep, that's exactly what your code is doing
every time the remote gets fired, a new connection to player.characteradded is created
because there is no limit, this is technically a memory leak because over enough time, or enough deaths, or if a cheater deliberately fires it without having died, this can reach hundreds to thousands, infinitely many connections. and each connection takes up a small amount of memory. it never gets cleared until the player leaves so if the player stays long enough this could eventually crash a server - though it's unlikely because how many times the player has to fire the remote for it to cause a crash, it's still a memory leak.
so even though the characteradded isnt going off when the remote event is fired its creating a connection? (whats a connection?)
yes it creates a new connection
the :Connect() is a connection
you could use :Once() but you're using it wrong in the first place
if you wanna keep it there do :Once()
so how do i move it somewhere else? and get rid of the connection?
When you are trying to restore the player purchase
well thats why i was asking what are you trying to do exactly
where are you storing that bool
Restoring player purchase as a bool
in the client tho?
this doesn't make sense and doesn't answer the question
hes trying to restore a purchase
that is x5booleansave
the sentence 'restore a purchase' makes 0 sense to me
you are restoring it when joining another instance
which can be considered save load
and it doesnt have anything to do with characteradded
i'm asking to find out why characteradded and the remote is there
🤷
why not just characteradded:connect( APPLY_PURCHASE(char) ) ??? is that what they're trying to do? like this is why i asked and you should let them answer
^
just trust the process bruh
👍
this is a very real phenomenon and pushing people into explaining the problem they're having better and with more clarity and precision helps a lot with that. sometimes all it takes is asking the right question 👍
when a player dies, the boolean that gets turned to true when they buy a gamepass then gets turned to false and I want it to remain true so to do that when the player first loads into the game the datasave fires to the server the boolean it saved when the player bought the gamepass then when the client receives itr and it equals true, the client fires back to the server the same boolean so the part where the infinite connections is knows what boolean it is so then if a player dies characteradded can go off and return the boolean back to the client
oh so its a gamepass?
yeah
just see if the player owns it when rejoining
okay that makes a bit more sense, a few things to unpack here: firstly, never trust the client to tell you when they own a gamepass. use players:userownsgamepassasync()
yeah that's it. marketplaceservice/players close enough 
also for some reason
this method
doesnt actually update
when the player buys it ingame
yes also capture promptgamepasspurchasefinished
or unowns the gamepass
so apply it with this upon purchase
assume the player maintains ownership until the session is completed and you check again on their next join
and also use ownsgamepass to check when rejoining
so ignore unowning it
i mean no one would disown a gamepass anyway
that's the first step - capturing when the player owns the gamepass and when they do not
just a detail
it works after player buys it in the game if thats what ur asking
yandere simulator code
what
just a word of advice you should not stack the gamepasses like this, they should be additive, not absolute. this means that if i go onto the game's shop (on roblox.com, not in the roblox player) and manually by the x5 speed, i should only have x2 speed if i don't already have the first speed bonuses
make a table
but anyway okay it seems like we narrowed down the problem - you apply the speed bonus to the player's character, but only their first character. you want it to apply to every subsequent character like if they die and respawn
that's simple enough
yo ur smart
yeah
doing this is very simple - store the result of however you capture the gamepass ownership, then apply it on characteradded
you don't need any remotes to :fireserver to do this, the server should already know in advance whether the player owns the gamepass or not. do not trust the client to tell the server if they own the gamepass or not.
so i should userownsgamepassasync?
yes, store a table that holds the results of userownsgamepass when the player first joins, then update this table when the promptgamepasspurchasefinished is fired - you also need to update the current character when this happens
then whenever the player's characteradded is called, you can just refer to this table.
also why refer gamepasses by name instead of id
instead of doing a ladder of if
store the ids in a table
and retrieve upon purchase finished
so instead of having 50 gamepasses and 50 ifs you have 4 lines
the table would look something like ```lua
local playerGamepasses = {
[my_userid] = {
["x2Speed"]= marketplaceservice:UserOwnsGamepass(my_userid); -- etc, do this in playeradded
["x3Speed"]=false;
["x4Speed"]=true;
}
}
function applyGamepassSpeed(player)
local passes=playerGamepasses[player.UserId]
local speedbonus=1
if passes["x2Speed"] then speedbonus+=1 end
if passes["x3Speed"] then speedbonus+=2 end
...etc
-- remote:fireclient(player,speedbonus)
-- or player.character.humanoid.WalkSpeed=16*speedbonus, or whatever else
end```
then just call the apply function on the purchase event, and on characteradded
very simple 👍
local cooltable = {
1234 = { name = "2xSpeed" }
}
MPS.PromptGamePassPurchaseFinished:Connect(function(player,id,purchased)
if not purchased then return end
local data = cooltable[id]
print(player.Name,"bought", data.name)
speedevent:FireClient(player,data.name)
end)```
more future proof
like this?
ignore local speedboost = 1
and the player part of the applyspeedpass after characteradded
function applyspeedpass(player)
...
applyspeedpass()``` please test your code before asking 
always know what's in your variables, never assume. debug everything.
but generally the shape of it looks fine, you don't need gamepasstable[player] if you're doing it like this since the gamepasstable is an upvalue and only exists for that one player
i'll say this, you're quite a long way away from s1 rank 
only edge case left i can see really is if the player's character gets added before the player is ready to receive remotes, but aside from that close enough i guess 🤷
had to change it to this cuz "player.UserId" wasnt working in the table but now it works, im assuming that it prints false at the top cuz i dont actually own the gamepass after buying it
thx for all ur guys help
you need to update the table in the prompt
@tiny ingot @karmic sonnet never use PromptGamepassPurchaseFinished for handling purchased products
use ProcessReceipt
should maybe double check your facts before pinging 2 people
PromptGamepassPurchaseFinished does not fire for devproducts.
ProcessReceipt does not fire for Gamepasses
hope that clears up your misunderstanding, i know what you're talking about and that's only an issue for devproducts, not gamepasses.

oh yeah that's right
based on the research i did, people who already have a gamepass can still fire the purchasefinished multiple times but they have to actually own the gamepass first, so design accordingly - gamepasses should not be tied to consumable or temporary bonuses 👍