Why does my Roblox joining badge not work? - roblox

I made a visiting or thanks for joining badge that I made to be given to any new person that joins my game, but it only works sometimes.
I couldn't try anything, the badge gave it to 60 people when 146 people joined! All 146 people were supposed to get it!
This is the badge code:
local badgeID = 2124446943
local badgeService = game:GetService("BadgeService")
function onEntered(player)
wait(1)
if not badgeService:UserHasBadge(player.UserId, badgeID) then
badgeService:AwardBadge(player.UserId, badgeID)
end
end
game.Players.PlayerAdded:Connect(onEntered)
It was supposed to be given to all the people who visited. Because at some point they were all new!

It is an unlikely possibility that only 60 unique people have played your game, but all of them played your game at least twice resulting in 146 visits
Another possibility is that some players disconnect before the wait(1) in your function, so maybe try this:
function onEntered(player)
repeat wait(0.1) until player ~= nil
if not badgeService:UserHasBadge(player.UserId, badgeID) then
badgeService:AwardBadge(player.UserId, badgeID)
end
end
end
But I don't think that'll have any effect because the player can't be nil if they've entered... (idk it's a random suggestion don't count on me)
Sorry I wanted to comment instead of typing here but I need 50 reputation to do so

Related

Roblox Studio- Infinite yield possible

I am trying to code a FPS Game but when I tap the button to pick a gun it does not give it to me but instead says Infinite yield possible, anyways this is my code:
game.ReplicatedStorage.RemoteEvents.AKEvent.OnServerEvent:Connect(function(player)
local ak = game.ReplicatedStorage.Weapons.AK:Clone()
ak.Parent = player:WaitForChild("BackPack")
end)
In very little time I have already found what happened, so if it happens to you:
Backpack had a capital P and it was meant to be with a lower case P lol!

Roblox - detect if mesh is hit by hand

I am not sure where to start so asking for some help. I want to create a script that detect if a certain mesh is hit by players right hand. Every time the mesh is hit I want to increase points for player by 1.
Anyone who can nudge me in the right direction here?
Thanks!
EDIT:
I have added this script in StarterCharacterScripts:
game.Players.LocalPlayer.Character:WaitForChild("RightHand").Touched:Connect(function(hit)
local part1 = workspace.CoinsClouds["Meshes/SackOfGoldNoCoins1"]
part1.Touched:Connect(function(hit)
if hit.Name == "RightHand" then
print(hit.Name)
end
end)
end)
This will register when I bump into the part with the right hand, BUT it will register it 5-20 times in a split second every time I bump into the part with the right hand. See attached image. Anyone know why? I would like it to register only once when the right hand is bumped against the part, or even better, only when the user punch the part/mesh. I have tried to add a wait after RightHand is found, but that doesn't work.
PS! I don't know if this is the right way to script it...
Below is an example of the code you would use. It will check if your part is touched by either the right or left hand and it will run whatever is inside of your if statement, in this case it will increase whatever your score is by 1.
local part = workspace.Part -- reference the part here
local debounce = false --used to check for debounce
part.Touched:Connect(function(hit)
if hit.Name == "RightHand" or "LeftHand" then -- checks if a hand touched it
if not debounce then --Check that debounce variable is not true
debounce = true --currently touching the part
print("hit")
wait(1)
debounce = false
end
end
end)
In relation to your new question it is to do with debounce. Roblox has an entire article on it here: https://developer.roblox.com/en-us/articles/Debounce
Basically you would have to add a new if statement to check that the player isn't already touching this part if it is it wont repeat the what is inside the if statement. The code sample above has been edited to work with debounce.

How can I get statements within functions to execute in a randomly chosen order?

I'm relatively new to Matlab, and I've been trying to solve my problem for ages but I'm just continuously arriving at a dead end.
I have a code which should, in theory, play 3 sounds in a random order (each order being different for each trial). Upon each sound playing the participant will be asked which sound they heard and then given feedback. I have all the code complete and working up until the random order part. I have created code that on each trial will randomly order 1,2 and 3.
Order = [1, 2, 3];
PhonemeOrder = randperm (numel(Order));
I then have a function which plays the sound/asks the questions etc. within this I have attempted switch cases statements and if else statements depending on the number that PhonemeOrder produces but the order doesnt change even when phoneme order does. I believe my problem is however that PhonemeOrder comes out like [1,2,3] or [3,1,2] which is what i wanted. but Im not sure how to get my sounds to play in the order that it shows because I am using code like...
if/ PhonemeOrder = 1;
then do this...
elseif phonemeorder = 2;
then do this...
else
do this...
Or I've tried code like
switch cases
case 1
do this
case 2
do this
case 3
do this
I'm guessing this is where i am going wrong, but i just dont know how to change it and make it work! I hope this makes sense? I just need it to play in the order that phonemeorder specifies, with the order changing on each trial.
Any help will be greatly appreciated :D
bexG,
I think you are on the right track.
The only thing you need is to use a "for-loop" to go through the array of PhonemeOrder.
for i=1:length(PhonemeOrder)
switch PhonemeOrder(i)
case 1
play the first song
case 2
play the second song
case 3
play the thrid song
end
end
I hope this will help.
Please let me know if you have any further question.

Editing Timeline from CCB file in cocos

I did some research into this and couldn't really find anything, so if this is a repetitive question I apologize. but anyway I have made a CCB file in CocosBuilder and I would like to start the timeline, for example, at one second instead of playing from the beginning. Is there a way to do this? Thanks for the help guys.
Edit: i would like this to be done in the code.
I am using 2.2.1 Cocos2DX version. I think there is no option to play it from given interval. But you can tweak yourself to get it done. (Not simple one)
You have to go to CCBAnimationManager and there you get "mNodeSequences".
It is dictionary and you get difference properties there like "rotation position etc..."
values there.
Internally AnimationManager reads this value (These values are specified in your CCB)
and puts in runAction queue.
So you have to break it as you want.(Ex. 5 min timeline you have. But you want to start
from 1 min then you have run first 1 min Actions without delay and for remaining you
have properly calculate tween intervals.
It's long procedure and needs calculation. If you don't know any other simpler way try this. If you know pls let us know (Post it).

Facebook Koala loop not working properly

The following is the code that does not work -
for x in #y
v = #graph.get_object("me") # This is not a useful code. I'm just trying to make a point
end
While the following code works
u = #graph.get_object("me")
for x in #y
v = u
end
I'd appreciate help with this issue. Thanks!
I tried testing something similar to this in the console, and saying something like
for i in 1..1000
#graph.get_object("me")
end
and after some amount of time, it finally finished.. but it took a while. I'm assuming there's a chance the connection between you and facebook can get blocked/closed/timeout.
Every call took about a second. I think the problem is that facebook's API has a bandwidth limit. So, in the case of your first block of code, you're calling get_object over and over, where as in the second one, you are simply calling the API once, then just assigning that value over and over.