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

How do I make it only apply if the player owns the asset?

This script is inside the server script service. Here is the script:

game.Players.PlayerAdded:connect(onPlayerRespawned)
function onPlayerRespawned(newPlayer)
	wait(1)
		if game.MarketplaceService:PlayerOwnsAsset(newPlayer, 4692779138) then
			script.Parent.VIP.Active = true
			if newPlayer.Name == "CJ_Angel" then
				script.Parent.VIP.TextColor3 = Color3.fromRGB(0,58, 175)
				script.Parent.VIP.Text = ("~ V I P ~")
			end
			else script.Parent.VIP.Active = false
		end
		end

function onPlayerEntered(newPlayer)
	newPlayer.Changed:connect(function (property)
		if (property == "Character") then
			onPlayerRespawned(newPlayer)
		end
	end)
end

game.Players.PlayerAdded:connect(onPlayerEntered)

1 answer

fix:

function onPlayerEntered(newPlayer)
    newPlayer.Changed:Connect(function (property)
        if (property == "Character") then
            onPlayerRespawned(newPlayer)
        end
    end)
    function onPlayerRespawned(char)
    wait(1)
        if game.MarketplaceService:PlayerOwnsAsset(newPlayer.UserId, 4692779138) then
            script.Parent.VIP.Active = true
            if newPlayer.Name == "CJ_Angel" then
                script.Parent.VIP.TextColor3 = Color3.fromRGB(0,58, 175)
                script.Parent.VIP.Text = ("~ V I P ~")
            end
        else script.Parent.VIP.Active = false
      end
end
end

game.Players.PlayerAdded:Connect(onPlayerEntered)
game.Players.PlayerAdded:connect(onPlayerRespawned)

not tested

1 comment

0

Didn't work, output error: 10:38:24.151 - Unable to cast value to Object

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