Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

[SOLVED] Tools working inside studio local servers, but not when the game is published (?)

Tools working inside studio local servers, but not when the game is published.

The tool, just the linked sword as its just so I know the script is working, is able to be cloned into the players backpack inside studio, but not inside of a published server. I originally had the sword stored in ServerStorage, but moved it into ReplicatedStorage after hearing that there is the occasional issue with using ServerStorage, however this did not fix the problem. The script is not local, but server side and kept in ServerScriptService. It is also designed to easily expand for multiple passes, which is why it is kept in a dictionary with anonymous functions.

I started scripting in lua a couple days ago, so forgive any stupid beginner mistakes.

local RS = game:GetService("ReplicatedStorage")
local MPS = game:GetService("MarketplaceService") 

local rewards = 
{
	sword = function(player)
		print("Sword function called")
		local sword = RS:WaitForChild("ClassicSword")
		local newSword = sword:Clone()
		newSword.Parent = player.Backpack
		
		print("Function complete")
		
end ;
}

local rewardID =
{
	sword = 9466814;
}

MPS.PromptGamePassPurchaseFinished:Connect(function(player, passID, purchaseSuccess)
	if purchaseSuccess then
		for i, v in pairs(rewardID) do
			if passID == v then
				print(player.Name.." purchased "..tostring(i))
				rewards[i](player)
				
			end
		
		end
	end			
end)

game:GetService("Players").PlayerAdded:Connect(function(player)
	for i, v in pairs(rewardID) do
		if MPS:UserOwnsGamePassAsync(player.UserId, v) then
			print(player.Name.." has recieved "..tostring(i))
			rewards[i](player)
		end
		
	end
end)


It is also important to note that all print statements were successfully called and there were no errors during runtime in studio, nor the published server.

When using the console on any published server, no players who own the pass has the linked sword as their child and attempting to print the parent of the sword will return nil.

The sword will also, on rare occasions, work for some reason, and I am given the sword when I join.

Thanks in advance.

EDIT: Unrelated, but I do not know where else to put this. I disabled my adblocker for this site, because I use it regularly and want to support it, but ads cover important parts of the screen. Unsure if this is just me, but just was curious.

1 answer

SOLVED! The issue was that, even though I had WaitForChild(), it would still not set it the parent as backpack, for an odd reason. By adding a Wait(2) before assigning the parent, it now works 100% of the time

This discussion is preserved as it was. New answers, comments, and votes are closed.