Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Prompt Purchase on touch not working?

Asked by 5 years ago

Explorer: Model inside of workspace Part named head inside of model Humanoid in model Script inside of head:

local mps = game:GetService("MarketplaceService")
local ID = "I don't wanna share this model, but yes, i put a valid ID WITHOUT the speech marks."
function onHit(hit)
    if (hit.Parent:FindFirstChild("Humanoid") ~= nil) then
        if not mps:PlayerOwnsAsset(player,ID) then
        mps:PromptPurchase(player,ID)
    end
    end

I want it to prompt the purchase for the model once the part has been touched, however it doesn't seem to be working. Any help? I wasn't sure whether to use onHit or onTouch, but I tried both and they didn't work.

Thanks!

2 answers

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

You forgot script.Parent.Touched:Connect(onHit) and end There is the whole script:

local mps = game:GetService("MarketplaceService")
local ID = "I don't wanna share this model, but yes, i put a valid ID WITHOUT the speech marks."
function onHit(hit)
    if (hit.Parent:FindFirstChild("Humanoid") ~= nil) then
        if not mps:PlayerOwnsAsset(player,ID) then
        mps:PromptPurchase(player,ID)
    end
    end
end

script.Parent.Touched:Connect(onHit)
Ad
Log in to vote
0
Answered by
saenae 318 Moderation Voter
5 years ago
Edited 5 years ago

'onHit' and 'onTouch are just function names commonly used to connect to the .Touched event. If you're somewhat unfamiliar with events, the wiki gives some insight on how they're used here.

Also, your explanation of the explorer confused me a bit, so I just assumed that the script is placed inside of the object that's being touched by some player:

local mps = game:GetService("MarketPlaceService")
local ID = "I don't wanna share this model, but yes, i put a valid ID WITHOUT the speech marks."

function onHit(hit)
    if hit.Parent:FindFirstChild("Humanoid") then -- The '~= nil' isn't really necessary
        local player = hit.Parent
        if not mps:PlayerOwnsAsset(player, ID) then
            mps:PromptPurchase(player, ID)
        end
    end
end

local partToTouch = script.Parent -- your model
partToTouch.Touched:Connect(onHit) -- any time the part is touched, your function will fire.

I hope this helps!

0
Yes the ~= nil is not necessary neither is the lowercase "f" It's FindFirstChild, not findFirstChild User#19524 175 — 5y
0
My mistake, force of habit. saenae 318 — 5y

Answer this question