I want to prompt a player to buy my t-shirt when the player touches a part, but it doesn’t seem to be working.
This is my code:
local SHIRT_ID = 8896035930
script.Parent.Touched:Connect(function(otherPart)
local partParent = otherPart.Parent
local humanoid = partParent:FindFirstChild("Humanoid")
if humanoid then
game:GetService("MarketplaceService"):PromptPurchase(game.Players.LocalPlayer, SHIRT_ID)
end
end)
I don’t get any error messages. Help would be appreciated.
local SHIRT_ID = 8896035930
script.Parent.Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChildOfClass("Humanoid") then
game:GetService("MarketplaceService"):PromptPurchase(game.Players:GetPlayerFromCharacter(Hit.Parent), SHIRT_ID)
end
end)
LocalScripts CAN use the touched function, but they can not be inside of workspace or any other non-player related areas, meaning that it has to be under something related to the player and run from there.
You need to use Touchinterest instead then. But it has to be in a local script because you can’t call local player in a server script no matter what you do.
LocalScripts don’t work in workspace, they need to be a descendant of a Player or Character, you need to use a normal script, @Misinformater’s code should work.
This is true, but you can get a Player if you have the right info, like their Character. You can use game.Players:GetPlayerFromCharacter() or even just get the Player with the Characters name by going through game.Players[Character.Name].
This would only work if script.Parent is part of the player’s character, which is obviously not what OP wants.