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

What's the mistake in this script?

I've recently begun looking into Dev products and such so I began looking through free models to look at the scripts and try to learn from their codes. I came across this script and when I tested it out, I couldn't figure out why it wasn't working. Do any of you know why? And how I may fix it?

The concept of the script is to increase the speed of the buyer for 10 seconds. It is placed inside a gui button.

It opens up the prompt for people to buy the Dev Product and it allows for the purchase to take place. Although, for some reason, it does not increase the speed.

productId = 20656568 

local MarketplaceService = Game:GetService("MarketplaceService")
function UsernameFromID(ID)
	if type(ID) ~= "number" then
	return
	end
	local sets = game:service("InsertService"):GetUserSets(ID)
	for k, v in next, sets do
		if v.Name == "My Models" then
			return v.CreatorName
		end
	end
end
function giveRewards(player)
	player.Humanoid.WalkSpeed = 32
	wait(10)
	player.Humanoid.WalkSpeed = 16
	return Enum.ProductPurcaseDecision.PurchaseGranted
end
MarketplaceService.ProcessReceipt = function(receiptInfo)
	giveRewards(receiptInfo.PlayerId)
end
script.Parent.MouseButton1Down:connect(function()
	Game:GetService("MarketplaceService"):PromptProductPurchase(script.Parent.Parent.Parent.Parent, productId)
end)

1 answer

From a quick glance there is one glaring error. The player passed into this function is actually in game.Players whereas the Humanoid is in the workspace.

Therefore you should chance lines 16-18 with:


    Workspace:FindFirstChild(player.Name).Humanoid.WalkSpeed = 32
    wait(10)
    Workspace:FindFirstChild(player.Name).Humanoid.WalkSpeed = 16

This is the error I have found but I'm not sure if its the only error. -MD

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