Hello developers, I noticed yesterday and today that when I was following a tutorials on a script. I then published my game and of course thought it would work just like usual but no it doesn’t seem like it was running.
Thanks!
You should test out your scripts BEFORE publishing a game, even if you think you flawlessly followed a tutorial. Its a good habit. This way, players can get a very good first impression without any bugs.
What were you trying to achieve (like what did you want the scripts to do)?
I did test it in roblox studio it didn’t work so I thought it was mabye just a studio bug then I published it. (The script is supposed to be a invite friends gui)
Please show us the code and error(s) produced by your work.
Well I replaced the script with a free model script since it didnt work
I’ll just type it again I guess
Here’s the script:
local SocialService = game:GetService("SocialService")
local player = game.Players.LocalPlayer
function Invite()
local success, result = pcall(
function()
return SocialService:CanSendGameInviteAsync(player)
end
)
if result == true then
SocialService:PromptGameInvite(player)
end
end
script.Parent.MouseButton1Click:Connect(Invite)
script.Parent.TouchTap:Connect(Invite)
and there is no errors in the output
Is this code your first script or the script from the free model?
This was the original script from the tutorial I followed.
Is this a server script? I don’t see any other reason why this code shouldn’t work.
Its a local script in a text button.
Well thats what it says in the tutorial
This is how it should be I think. I made text button, copied the code and ran it. It worked fine for me.
i don’t think that’s a valid function
erase that because MoseButton1Click exists
when you’re doing a pcall, success is the bool value and result is the string to help store the error message if necessary
plus you can do if success then
and/or if not success then
instead of doing == true/false
I just want to give you a quick suggestion when there aren’t any errors in the output despite the script not working. Try putting print()
functions around the code. Then, when you run the script, you will be able to see in the output around where the script runs into a error (look at where the script stopped running the print()
command). Of course, this doesn’t ALWAYS work, but its a good trick to try.
You should try listening to the Button’s Activated
event instead of MouseButton1Click
. Another thing is to throw an error in-case the pcall fails - Since it’ll be easier for debugging.
local SocialService = game:GetService("SocialService")
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local Button = script.Parent
local function InviteFriends()
local Ok, Result = pcall(
SocialService.CanSendGameInviteAsync,
SocialService,
LocalPlayer
)
if not Ok then
return error(
string.format(
"[InviteFriends] - An unexpected error has been caught while attempting to Invite Friends:\n%s",
Result
), 3
)
end
SocialService:PromptGameInvite(LocalPlayer)
end
Button.Activated:Connect(InviteFriends)